在做项目的时候,需要使用一个侧滑菜单栏:
问题:
1.侧滑菜单的图标全部显示为灰色
menu布局
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_camera"
android:icon="@drawable/personal_mytask_btn"
android:title="@string/drawer_nav_mytask_str" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/personal_mysetting_btn"
android:title="@string/drawer_nav_mysetting_str" />
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/personal_myperformance_btn"
android:title="@string/drawer_nav_myPerformance_str" />
<item
android:id="@+id/nav_manage"
android:icon="@drawable/ic_menu_manage"
android:title="Tools" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_menu_share"
android:title="Share" />
<item
android:id="@+id/nav_send"
android:icon="@drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>
</menu>
activity的xml页面布局
<?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/app_bar_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>
代码实现
nav_view.setNavigationItemSelectedListener(this)
nav_view.itemIconTintList = null
效果图:
解决办法:
nav_view.setNavigationItemSelectedListener(this)
nav_view.itemIconTintList = null //显示原始颜色
//NavigationView设置属性app:itemIconTint为统一颜色