Android 更改listview行的背景颜色
我有一个导航抽屉活动。默认选定项目颜色为蓝色,我想将其更改为绿色 这是我的片段\u navigation\u drawer.xml:Android 更改listview行的背景颜色,android,xml,listview,navigation-drawer,Android,Xml,Listview,Navigation Drawer,我有一个导航抽屉活动。默认选定项目颜色为蓝色,我想将其更改为绿色 这是我的片段\u navigation\u drawer.xml: <ListView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#19A3A3"
android:dividerHeight="1dp"
android:background="@drawable/background"
android:textColor="@color/primary_material_dark"
tools:context=".NavigationDrawerFragment"
/>
我在drawables中创建了background.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_hovered="true" android:state_activated="true" android:state_checked="true" android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#00FF00" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/material_blue_grey_900" />
</shape>
</item>
</selector>
当我执行应用程序时,所选的listview项目仍然是蓝色的
有办法解决吗
<item android:state_hovered="true" android:state_activated="true"
android:state_checked="true" android:state_pressed="true">...</item>
如果希望其他州的行为相同,则必须为每个州添加一个新的…
条目
<item android:state_activated="true">...</item>