简体   繁体   English

如何在android导航抽屉中更改所选项目的背景颜色?

[英]How to change the selected item's background color in android navigation drawer?

I am using Navigation Drawer (using Navigation Drawer Activity) in android studio and its working fine. 我在android studio中使用导航抽屉(使用导航抽屉活动),并且工作正常。

But I want to change the Background Color of selected item in Drawer's item List. 但是我想更改抽屉项目列表中所选项目的背景颜色。 I want to change default Color to my custom Color. 我想将默认颜色更改为我的自定义颜色。

Any idea ??? 任何想法 ???

Create another xml layout under res ⇒ drawable named list_item_bg_pressed.xml with following content. 在res⇒Drawable下创建另一个xml布局,命名为list_item_bg_pressed.xml,内容如下。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"><gradient
  android:startColor="@color/list_background_pressed"
  android:endColor="@color/list_background_pressed"
  android:angle="90" />

Create Selector 创建选择器

<item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/>

For more info see this link Sliding drawer 欲了解更多信息请参阅此链接滑动抽屉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM