当我有2个导航抽屉时,如何更改右侧NavigationDrawer的图标
问题描述:
我的应用程序中有2个导航抽屉。如何更改右侧导航抽屉的图标?我看到的所有链接都在谈论一个导航抽屉案例,并使用ActionBarToggle解决。当我有2个导航抽屉时,如何更改右侧NavigationDrawer的图标
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_viewLeft"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer_left" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_viewRight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
app:menu="@menu/activity_main_drawer_right" />
</android.support.v4.widget.DrawerLayout>
答
您只能在工具栏的左侧显示导航图标。可能的解决方案将使用的菜单,包括导航抽屉图标从https://material.io/icons/
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search" android:icon="@drawable/ic_search_white_24dp"
android:title="@string/search"
app:showAsAction="always"
/>
<item
android:id="@+id/btnMyMenu"
android:icon="@drawable/ic_menu_white_24dp"
android:title="Right Side Menu"
myapp:showAsAction="always"/>
</menu>
在点击相应的使用
mDrawerLayout.openDrawer(Gravity.RIGHT);
然后隐藏和显示菜单中相应
@布局内/ activity_main btnMyMenu打开的抽屉我有一个工具栏。我也有下面的代码。 toolbar =(Toolbar)findViewById(R.id.toolbar); setSupportActionBar(toolbar); drawer =(DrawerLayout)findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); – sandeep
是的。我在两个抽屉上都有菜单选项。但请分享你的课程。它可能会给我或其他人一些想法。 – sandeep
我不想像汉堡菜单那样的动画。静态图标是我想要的 – sandeep