Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationView + selector + ripple effect state selected not working

I have searched all things and experimented but not luck with NavigationView.

itemIconTint, itemTextColor and itemBackground working with ripple effect. but problem is state selected not working in selector drawable

I have also created drawable-v21 and put ripple_navigation_selector.xml

My goal is when open drawer again previous selected item should be in yellow color eg. Notifications item

enter image description here

NavigationView inside 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 inside drawable-v21

<item
    android:id="@android:id/mask"
    android:drawable="@drawable/navigation_selector"/>
<item android:drawable="@drawable/navigation_selector"/>

navigation_selector.xml inside 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>

color string named left_light_yellow

<color name="left_light_yellow">#F6CE20</color>
like image 284
Kishore Jethava Avatar asked Oct 24 '15 07:10

Kishore Jethava


1 Answers

I think you have to make your menu items checkable

<item
        android:id="@+id/wishlist"
        android:checkable="true"
        android:title="Wishlist" />
like image 193
Georgian Benetatos Avatar answered Nov 02 '22 09:11

Georgian Benetatos