Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改listview行的背景颜色_Android_Xml_Listview_Navigation Drawer - Fatal编程技术网

Android 更改listview行的背景颜色

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

我有一个导航抽屉活动。默认选定项目颜色为蓝色,我想将其更改为绿色

这是我的片段\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_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>