问题描述
我尝试更改我的项目导航视图"菜单的颜色:
i try to change color of my item Navigation View menu :
styles.xml
styles.xml
<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
activated_background.xml
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:
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 ?
推荐答案
您没有在styles.xml文件中为Navigation View项的背景设置drawable.打开包含导航视图"窗口小部件的XML布局文件,然后将以下行添加到窗口小部件的属性中:
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"
如果您在使用"app"指针时遇到麻烦,请同时添加以下行:
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"
请注意,这只会更改所选列表项的背景颜色.如果您还希望更改图标和文本的颜色,请改用app:itemTextColor
属性.
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.
这篇关于Android-导航查看项目菜单背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!