android – 按下时设置ListView选择器颜色的问题
作者:互联网
我有以下ListView,并且已经跟随了这个SO问题的答案没有运气:
Android ListView Selector Color
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ARListView"
android:background="@drawable/transparent_background"
android:cacheColorHint="#00000000"
android:listSelector="@drawable/ar_selector"
android:drawSelectorOnTop="true">
这是我的ar_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@android:color/transparent" />
<item android:state_pressed="true"
android:drawable="@color/solid_red" />
<item android:state_focused="true"
android:drawable="@android:color/transparent" />
</selector>
当我按下ListViewItem时,没有任何内容出现.
解决方法:
Sheehan Alam,使用此代码: –
list_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg" />
<item android:state_pressed="true"
android:drawable="@drawable/gradient_bg_hover" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg_hover" />
</selector>
gradient_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#f1f1f2"
android:centerColor="#e7e7e8"
android:endColor="#cfcfcf"
android:angle="270" />
</shape>
gradient_bg_hover.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#18d7e5"
android:centerColor="#16cedb"
android:endColor="#09adb9"
android:angle="270" />
</shape>
标签:android,selector,listview,listviewitem 来源: https://codeday.me/bug/20190705/1383478.html