android - 如何在抽屉导航中创建下拉菜单(在 Android 中)?

标签 android android-fragments expandablelistview navigation-drawer

我希望能够创建一个抽屉导航,其中包含一些可扩展、可选择的项目和一些不可扩展的项目。 StackOverflow 上对类似我的问题的共识指向了 ExpandableListView 的解决方案(这甚至可能不适用于我的想法)。在大多数情况下,人们要求的是一种在 Nav Drawer 中分隔项目的方法,就像 GMail 应用程序对标签所做的那样,而不是我想要做的...

...基本上概述了 HERE enter image description 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/

相关文章:

android - 无法应用插件 Android Gradle 插件 3.0.0-alpha5 不能应用到项目中

不幸的是Android模拟器浏览器已停止

java - 如何使通用布局包含在其他布局中,但在 Android 应用程序开发中动态更改通用布局内的属性?

Android - ViewPager 问题中的 fragment 内的 fragment

android - 在 Expandable listView android 中重复 child

android - 通话或短信电话位置

java - OnListItem点击打开一个新的Fragment

android - 从另一个 fragment 调用一个 fragment 中的函数的正确方法是什么?

java - 可扩展 ListView subview 问题

android - 如何在 Android 中保存和恢复 ExpandableListView 的状态?