Tho*_*eld 9 navigation android drawer relativelayout android-support-library
我正在为我正在开发的这个应用程序添加一个导航抽屉,我已经浏览了互联网; 论坛,stackoverflow,android开发者文档,仍然没有找到一个很好的答案.
我知道可以在不使用这些内容的情况下完成此操作.我想知道的是怎么样.NsMenuAdapter模型使用标题,然后有这些函数
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
Run Code Online (Sandbox Code Playgroud)
这显然正在寻找一个行动吧.我尝试了几个不起作用的模型,我刚刚尝试完成的大模型位于此处如何添加Android导航抽屉标题旁边的图标(这与我下面的链接有关,该项目来自gitHub这里https://github.com/gabrielemariotti/androiddev/tree/master/NavigationDrawer).现在关键的是,我正在使用自定义布局(即相对布局与线性布局混合在一起),我真的迷失了我的下一步应该是为了让它工作.
旁注:当我在main_activity.xml(导航抽屉的实现)中只有ListView时,它会像想象的那样正确滑出.但我不能为我的生活弄清楚如何用数据填充它.我基本上需要3个标题,其中包含可点击的导航元素,元素旁边有图标.
我通过相对布局http://gmariotti.blogspot.com/2013/05/creating-navigation-drawer.html转向了这个模型我的大部分见解如何做到这一点但是他们使用动作/标题栏这是什么真的把我扔了一圈.
Pra*_*jan 13
实际上这很简单.比使用ActionBar更容易.我用几乎最简单的布局来写答案
让你的xml像这样:
<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 Drawer -->
<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 Drawer -->
<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>
Run Code Online (Sandbox Code Playgroud)
然后让你的活动像这样:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
而已.希望能帮助到你.
我知道可以在不使用这些内容的情况下完成此操作.我想知道的是怎么样.
步骤1:按照使用说明进行操作DrawerLayout,例如本培训指南中的步骤,跳过与操作栏相关的任何内容.
步骤#2:没有步骤#2.
虽然DrawerLayout 可以使用操作栏,但它不是必需的,实际上需要额外的设置.