在我的活动的主要布局中有ListView (一个派生的JazzyListView):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.toto.toto"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
<com.twotoasters.jazzylistview.JazzyListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
app:effect="cards"
app:max_velocity="0"
app:only_animate_fling="false"
app:only_animate_new_items="false"
/>
</RelativeLayout>
主布局设置一个颜色背景。
对于我的列表,我在这个布局中使用项目:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="@color/item_background" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp" />
...
</RelativeLayout>
在这里,@color/item_background的值与@color/background不同。因此,我的主要布局有一个背景颜色,具体和列表项目也。
使用该方法时,当我单击列表中的项时,就没有选定的背景状态,也没有在我的列表上应用的经典背景。
有人会知道我如何创建一个定制的选择器(也许?)或者其他的东西,我的项目有一个自定义的颜色,同时,当我点击项目,经典选择的背景效果被应用?
谢谢你的帮助。
西尔万
发布于 2014-01-17 16:33:56
您首先需要创建一个自定义选择器,您将使用它作为列表项的背景,如下所示:
item_background_selectable.xml (to be created in a drawable folder)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:state_pressed="true"
android:drawable="@color/item_background_pressed" />
<item android:drawable="@android:color/item_background" />
</selector>
然后在列表项布局中使用自定义选择器:
android:background="@drawable/item_background_selectable"
希望这有帮助;-)
https://stackoverflow.com/questions/21190779
复制相似问题