使用导航抽屉没有TitleBar中或动作条 [英] Using Navigation Drawer without TitleBar or ActionBar
问题描述
我添加一个抽屉式导航这个应用程序,我发展,我已经走遍了互联网;论坛上,计算器,android的开发者文档,仍然还没有找到一个很好的答案。
I'm adding a Navigation Drawer to this app that I am developing and I have scoured the internet; forums, stackoverflow, android developer documentation, and still have not found a great answer for this.
我知道这是可能做到这一点,而无需使用这些东西。我想知道的是如何。该NsMenuAdapter模型使用一个名称,然后还有这些功能
I know that it is possible to do this without using either of these things. What I am wondering is how. The NsMenuAdapter model uses a title, and then there are these functions
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
这显然是在寻找一个动作吧。我尝试了几个模型,没有工作,大个我只是做了努力就设在这里<一href="http://stackoverflow.com/questions/16874826/how-to-add-icons-adjacent-to-titles-for-android-navigation-drawer">How添加毗邻标题为Android导航抽屉(这与我下面的链接图标,该项目是从GitHub上这里<一href="https://github.com/gabrielemariotti/androiddev/tree/master/NavigationDrawer">https://github.com/gabrielemariotti/androiddev/tree/master/NavigationDrawer).现在的关键是,我使用的是自定义布局(混在线性布局,即相对布局),我真的失去了什么我的下一个步骤应该是为了得到这个工作。
Which are clearly looking for an action bar. I tried a couple of models that didn't work, the big one I just got done trying is located here How to Add icons adjacent to titles for Android Navigation Drawer (which is related to the link I have below, the project is from gitHub here https://github.com/gabrielemariotti/androiddev/tree/master/NavigationDrawer). Now the key thing is, I am using a custom layout (i.e. Relative Layouts mixed in with Linear Layouts) and I'm really lost on what my next step should be in order to get this to work.
旁注:当我只有在我main_activity.xml(的实现导航抽屉)在ListView它正确地滑出喜欢它是假设。但我不能为我的生活弄清楚如何填充数据。我基本上需要3头与将在其中点击导航元素,用图标旁边的元素。
Sidenote: When I only have the ListView in my main_activity.xml (the implementation for the Navigation Drawer) it does properly slide out like it is suppose to. But I cannot for the life of me figure out how to populate it with data. I basically need 3 headers with that will have clickable navigation elements in them, with icons next to the elements.
我转过身来,这款型号为我的大部分有识之士就如何通过相对布局做到这一点<一个href="http://gmariotti.blogspot.com/2013/05/creating-navigation-drawer.html">http://gmariotti.blogspot.com/2013/05/creating-navigation-drawer.html但是,他们用行动/标题栏这是什么是真正扔我一个循环。
I turned to this model for most of my insight on how to do this via Relative Layouts http://gmariotti.blogspot.com/2013/05/creating-navigation-drawer.html But they use action/title bars which is what is really throwing me for a loop.
推荐答案
这是很简单的实际。比动作条更容易。我写的答案几乎最简单的布局
It's quite simple actually. Easier than with ActionBar. I'm writing the answer with almost simplest of layouts
让你的XML是这样的:
make your xml something like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- This is how your main page will look, just 2 buttons -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:onClick="onLeft"
android:text="left" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:onClick="onRight"
android:text="right" />
</RelativeLayout>
<!-- Left Drawrer -->
<RelativeLayout
android:id="@+id/whatYouWantInLeftDrawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark" />
<!-- you can have many more widgets here like buttons or labels -->
</RelativeLayout>
<!-- Right Drawrer -->
<RelativeLayout
android:id="@+id/whatYouWantInRightDrawer"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light" />
<!-- you can have many more widgets here like buttons or labels -->
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
然后,让您的活动是这样的:
Then make your activity something like this:
public class MainActivity extends Activity {
RelativeLayout leftRL;
RelativeLayout rightRL;
DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I'm removing the ActionBar.
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
leftRL = (RelativeLayout)findViewById(R.id.whatYouWantInLeftDrawer);
rightRL = (RelativeLayout)findViewById(R.id.whatYouWantInRightDrawer);
drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
}
public void onLeft(View view)
{
drawerLayout.openDrawer(leftRL);
}
public void onRight(View view)
{
drawerLayout.openDrawer(rightRL);
}
}
就是这样。希望它能帮助。
That's it. Hope it helps.
这篇关于使用导航抽屉没有TitleBar中或动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!