2012-11-29 58 views
0

我想自定义在ListView项目的选择效果,但我不认识路。如何自定义的ListView Seletion Android中

将是有益的,如果我要更改选择项目的背景,不同的PNG当用户选择该项目。

有什么建议吗?

+0

你想在列表视图图标?你的问题不清楚。 – NewUser

+0

这听起来像是一个设计问题。 – mango

+0

没有我想要的方式来改变Android的列表视图...默认选择效果(在默认情况下,Android的列表视图,当你点击一个项目这成了像蓝) – AndreaF

回答

1

使用这个选择:

<ListView android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:divider="@null" 
     android:dividerHeight="0dip" 
     android:listSelector="@drawable/list_selector" /> 

选择:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" 
     android:state_pressed="false" 
     android:drawable="@drawable/yourdrawable" /> 
    <item android:state_focused="true" 
     android:state_pressed="true" 
     android:drawable="@drawable/yourdrawable" /> 
    <item android:state_focused="false" 
     android:state_pressed="true" 
     android:drawable="@drawable/yourdrawable" /> 
    <item android:drawable="@drawable/yourdrawable" /> 
</selector> 

这是一个good tutorial它。