我希望能够创建一个抽屉导航,其中包含一些可扩展、可选择的项目和一些不可扩展的项目。 StackOverflow 上对类似我的问题的共识指向了 ExpandableListView
的解决方案(这甚至可能不适用于我的想法)。在大多数情况下,人们要求的是一种在 Nav Drawer 中分隔项目的方法,就像 GMail 应用程序对标签所做的那样,而不是我想要做的...
...基本上概述了 HERE
和SIMILARLY HERE (though all, not some are dropdowns) .而且不喜欢THIS ANSWER .
最佳答案
在 DrawerLayout 中使用 ExpandableListView,如下所示:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_commentary_behind_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:text="Frame text" />
</FrameLayout>
<!-- The navigation drawer -->
<ExpandableListView
android:id="@+id/left_drawer2"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="multipleChoice"
android:dividerHeight="0dp"
/>
</android.support.v4.widget.DrawerLayout>
然后像这样在代码中初始化:
private DrawerLayout drawer;
private ExpandableListView drawerList;
private CheckBox checkBox;
private ActionBarDrawerToggle actionBarDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_layout);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout2);
drawerList = (ExpandableListView) findViewById(R.id.left_drawer2);
drawerList.setAdapter(new NewAdapter(this, groupItem, childItem));
}
关于android - 如何在抽屉导航中创建下拉菜单(在 Android 中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29067696/