NavigationView theme selected item background style

时间秒杀一切 提交于 2019-12-06 04:28:16

You don't have to customize the style for this one, you can set a Color State List to the NavigationView app:itemTextColor.


Example:

NavigationView:

<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:itemTextColor="@color/nav_state_list"
    app:headerLayout="@layout/nav_header_drawer"
    app:menu="@menu/activity_drawer_drawer" />

Create a nav_state_list.xml file in your res/color and put this inside:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Item checked -->
    <item android:color="#313189" android:state_checked="true" />
    <!-- Item pressed -->
    <item android:color="#318931" android:state_pressed="true" />
    <!-- Item default -->
    <item android:color="#893131" />
</selector>

This is how it will look after:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!