Wednesday, April 15, 2015

Android : Change a listview row background color



I have a navigation drawer activity. The default selected item color is blue, I want to change it to green.


Here is my fragment_navigation_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"
/>


I created the background.xml in drawables:



<?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>


When I execute the app, the selected listview item still is blue.


Any ideia to solve it?


No comments:

Post a Comment