NavigationView + selector + ripple effect state selected not working
Asked Answered
K

2

8

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>
Kristiekristien answered 24/10, 2015 at 7:17 Comment(4)
did you solve this issue?Knurled
works without rippleKristiekristien
I opened a related question: #37797370Reseta
My plus one point for SRT photoMoraine
F
5

I think you have to make your menu items checkable

<item
        android:id="@+id/wishlist"
        android:checkable="true"
        android:title="Wishlist" />
Flack answered 8/3, 2016 at 9:7 Comment(0)
A
0

Why do you have 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"
        />

I think that if you remove the "1" it should work:

       ...
       app:itemBackground="@drawable/ripple_navigation_selector"
        />
Ascham answered 17/3, 2016 at 22:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.