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
352 views
in Technique[技术] by (71.8m points)

Android - Navigation View item menu background color

i try to change color of my item Navigation View menu :

styles.xml

<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>

activated_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/White" />
    <item android:state_focused="true" android:drawable="@color/White" />
    <item android:state_activated="true" android:drawable="@color/White" />
    <item android:drawable="@android:color/transparent" />
</selector>

drawer.xml :

<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">

<group
    android:id="@+id/group_1">
    <item
        android:id="@+id/drawer_menu_account"
        android:checked="false"
        android:title="@string/menu_account"
        android:icon="@drawable/ic_account_grey600_24dp" />
    <item
        android:id="@+id/drawer_menu_my_post"
        android:checked="false"
        android:title="@string/menu_my_post"
        android:icon="@drawable/ic_pin_grey600_24dp" />
</group>
[...]

Background color don't change.. What am i doing wrong ?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You don't set the drawable for the background of a Navigation View item in your styles.xml file. Open up your XML layout file containing your Navigation View widget, and add the following line to the widget's attributes:

app:itemBackground="@drawable/activated_background.xml"

If you're having trouble with the "app" pointer, add the following line in as well:

xmlns:app="http://schemas.android.com/apk/res-auto"

Note that this only changes the colour of the background of a selected list item. If you'd like the icon and text colour to change as well, use the app:itemTextColor attribute instead.


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

...