Showing posts with label How to change color of ListView items on focus and on click. Show all posts
Showing posts with label How to change color of ListView items on focus and on click. Show all posts

Wednesday, 10 June 2015

How to change color of ListView items on focus and on click.

In Custom ListItem Layout :


<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/NevDrawerItemLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:layout_gravity="center_vertical">

//Do put all controls like textbox..images
</LinearLayout >

now Create Xml file in Drawable Folder :

list_background.xml

<?xml version="1.0" encoding="utf-8"?>
     <selector xmlns:android="http://schemas.android.com/apk/res/android">

         <item android:state_focused="true" android:drawable="@color/list_background" />
        <!-- focused -->

         <item android:state_pressed="true" android:drawable="@color/list_background_pressed" />
        <!-- pressed -->

        <item android:drawable="@color/list_background" />
        <!-- default -->

</selector>