我正在使用片段而不是导航视图。我想在单击片段项时设置自定义颜色突出显示。
答案 0 :(得分:0)
MY scuode code:---
use within Navitaionview--app:itemBackground="@drawable/nav_item_background"
like Example:--
<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"
android:background="@color/nav.background"
app:menu="@menu/menu_drawer"
app:itemBackground="@drawable/nav_item_background"
nav_item_background.xml:---
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/nav.item.background" />
<item android:state_checked="true" android:drawable="@color/nav.item.background" />
<item android:state_focused="true" android:drawable="@color/nav.item.background" />
<item android:state_activated="true" android:drawable="@color/nav.item.background" />
<item android:drawable="@color/nav.item.background.default" />