【问题标题】:Changing the Navigation Drawer menu on click单击时更改导航抽屉菜单
【发布时间】:2017-07-14 10:52:20
【问题描述】:

我创建了一个基本导航菜单抽屉。我想要做的是在单击选项时更改导航菜单布局。 例如:我的菜单有男士、女士、儿童。当我点击男士时,我想在同一个导航抽屉中加载另一个列表,其中包含牛仔裤、衬衫等的菜单。

我已经在 ListView 中创建了两个列表,但是我无法在单击第一个菜单时在导航抽屉中扩展列表。 我已经检查了谷歌和 Stackoverflow,但似乎没有答案。

任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 使用消耗性列表视图在抽屉中制作子菜单。
  • @VishalChauhan 我知道,但这不是我想要的。我希望通过使用新菜单来完全更改导航菜单。

标签: android listview navigation drawer


【解决方案1】:

正如您在评论中所说,您想完全更改导航菜单,然后不要直接在抽屉布局中创建 ListView 或导航视图。

在 Drawer 布局中将导航菜单作为一个片段,在片段布局 xml 中,您可以创建一个列表视图。然后您可以轻松地将一个片段(包含菜单和子菜单列表)替换为另一个片段。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout  
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout"
android:background="#ffffff">

//main content view
<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!-- The drawer is given a fixed width in dp and extends the full height of
   the container. -->
<fragment android:id="@+id/navigation_drawer"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="Your's Base menu list fragment"
    tools:layout="@layout/drawer_drawer" />

 </android.support.v4.widget.DrawerLayout>

希望这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 2016-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多