我搜索了所有内容并进行了实验,但没有运气NavigationView
。
itemIconTint
,itemTextColor
和itemBackground
使用ripple
效果。但问题是state selected
无效selector drawable
我还创建了drawable-v21
并放置ripple_navigation_selector.xml
main_layout.xml 中的我的目标是当再次打开抽屉时,之前选择的项目应该在 黄色例如。通知项目
NavigationView
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/black"
app:headerLayout="@layout/header"
app:itemIconTint="@drawable/navigation_view_icon_tint_selector"
app:itemTextColor="@drawable/navigation_view_text_selector"
app:menu="@menu/drawer"
app1:itemBackground="@drawable/ripple_navigation_selector"
/>
ripple_navigation_selector.xml
内{p> drawable-v21
<item
android:id="@android:id/mask"
android:drawable="@drawable/navigation_selector"/>
<item android:drawable="@drawable/navigation_selector"/>
navigation_selector.xml
内的 drawable-v21
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@color/left_light_yellow" android:state_pressed="true"></item>
<item android:drawable="@color/left_light_yellow" android:state_activated="true"></item>
<item android:drawable="@color/left_light_yellow" android:state_checked="true"></item>
<item android:drawable="@android:color/black"></item>
名为left_light_yellow
<color name="left_light_yellow">#F6CE20</color>
答案 0 :(得分:3)
我认为您必须使菜单项可检查
<item
android:id="@+id/wishlist"
android:checkable="true"
android:title="Wishlist" />
答案 1 :(得分:0)
为什么你有app1?
<android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_width="250dp" android:layout_height="match_parent" android:layout_gravity="end" android:background="@color/black" app:headerLayout="@layout/header" app:itemIconTint="@drawable/navigation_view_icon_tint_selector" app:itemTextColor="@drawable/navigation_view_text_selector" app:menu="@menu/drawer" app1:itemBackground="@drawable/ripple_navigation_selector" />
我认为如果你删除“1”它应该有效:
...
app:itemBackground="@drawable/ripple_navigation_selector"
/>