Problem setting ListView selector color when pressed

こ雲淡風輕ζ 提交于 2019-12-04 09:04:27
Sam

Sheehan Alam, use this code:-

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!