当前位置:   article > 正文

Android 中listview点击一个item时背景色的设置_android listview 点击背景颜色

android listview 点击背景颜色

1.在values中添加一个colors的xml文件应于调用。

2.在drawable中添加一个item_selector.xml文件,用于供listview调用。

3.在listview中进行对点击时背景改变时调用。

colors.xml文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <color name="transparent">#00000000</color>// 透明的 当默认的时候也就是不进行点击事件的时候进行调用。
  4. <color name="choose">#9fb01513</color>//当点击时需要显示的颜色。
  5. </resources>

item_selector.xml文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  3. //默认不被按压的状态
  4. <item android:drawable="@color/transparent" android:state_pressed="false"/>
  5. //按钮被按压下的状态
  6. <item android:drawable="@color/choose" android:state_pressed="true"/>
  7. </selector>
在listview中设置的值:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical">
  6. <ListView
  7. android:id="@+id/lv_show"
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. <span style="color:#FF0000;">android:listSelector="@drawable/item_selector"</span> //对颜色的改变的调用。
  11. />
  12. </LinearLayout>

















声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/170788
推荐阅读
相关标签
  

闽ICP备14008679号