Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
72 views
in Technique[技术] by (71.8m points)

java - state_last selector's attribute doesn't work in navigation drawer

I want to change the background color of the last item of the navigation drawer menu, i implemented a selector so if state_last is true the color is red, otherwise, white, but it looks like that state_last is always false, here is the selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_last="true" android:drawable="@android:color/holo_red_dark" />

  <item android:state_last="false" android:drawable="@android:color/white" /> 
</selector>

here is the navigation code

   <com.google.android.material.navigation.NavigationView
    android:id="@+id/navView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/nav_menu"
    app:headerLayout="@layout/header"
    android:background="@color/blue1"
    app:itemTextColor="@color/blue1"
    app:itemBackground="@drawable/menu_item_background_color"
    app:itemIconTint="@color/blue1"
    />

i also tried to setActionView but also doesn't work, something else, is there a way other than adding empty items to make the last item in the end of the drawer?

question from:https://stackoverflow.com/questions/65932179/state-last-selectors-attribute-doesnt-work-in-navigation-drawer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...