8

我已经搜索了所有东西并进行了实验,但没有运气NavigationView

itemIconTintitemTextColoritemBackground有效地工作ripple。但问题state selected不起作用selector drawable

我还创建drawable-v21并放置ripple_navigation_selector.xml

我的目标是再次打开抽屉时,之前选择的项目应该是黄色的,例如。通知项目

在此处输入图像描述

NavigationView在 main_layout.xml 里面

  <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里面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>
4

2 回答 2

5

I think you have to make your menu items checkable

<item
        android:id="@+id/wishlist"
        android:checkable="true"
        android:title="Wishlist" />
于 2016-03-08T09:07:59.680 回答
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"
        />
于 2016-03-17T22:14:21.320 回答