user182944
user182944

Reputation: 8067

Android:Styling ListView

I want to put some style in the ListView in such a way that when an item of ListView is hovered, the color of that list item changes. I dont have any idea about how to achieve this.

Please suggest some other ideas about styling the ListView as well.

Regards,

Upvotes: 2

Views: 3241

Answers (1)

Arif Nadeem
Arif Nadeem

Reputation: 8604

Use selector to define what should happen when you focus the item, select the item and press the item, I doubt you cannot hover over a view, since Android devices use touch screen interface and not a pointing interface like a mouse..

This should help you:

Create a XML file in drawable folder named listselector.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/blue" /> <!-- focused -->
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/blue" /> <!-- focused and pressed-->
    <item android:state_pressed="true" android:drawable="@color/green" /> <!-- pressed -->
    <item android:drawable="@color/white" /> <!-- default -->
 </selector>

Then set the background of your TextView which you use in ListView to this like

android:background = "@drawable/listselector",

that should do it.

Upvotes: 1

Related Questions