2017-10-21 70 views
0

我的应用程序中有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> 
+0

@布局内/ 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

+0

是的。我在两个抽屉上都有菜单选项。但请分享你的课程。它可能会给我或其他人一些想法。 – sandeep

+0

我不想像汉堡菜单那样的动画。静态图标是我想要的 – sandeep

回答

2

您只能在工具栏的左侧显示导航图标。可能的解决方案将使用的菜单,包括导航抽屉图标从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); 

然后隐藏和显示菜单中相应

+0

查看此https://play.google.com/store/apps/details?id=com.myntra.android – sandeep

+0

此应用正在使用菜单项。点击菜单项,抽屉我们从右侧打开 –

+0

我有下面的操作栏菜单。右侧的图标来自文件下方。改变了图标,它工作。

sandeep