Android 中listview点击一个item时背景色的设置
2015-11-07 12:37
603 查看
1.在values中添加一个colors的xml文件应于调用。
2.在drawable中添加一个item_selector.xml文件,用于供listview调用。
3.在listview中进行对点击时背景改变时调用。
colors.xml文件:<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#00000000</color>// 透明的 当默认的时候也就是不进行点击事件的时候进行调用。
<color name="choose">#9fb01513</color>//当点击时需要显示的颜色。
</resources>
item_selector.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
//默认不被按压的状态
<item android:drawable="@color/transparent" android:state_pressed="false"/>
//按钮被按压下的状态
<item android:drawable="@color/choose" android:state_pressed="true"/>
</selector>在listview中设置的值:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lv_show"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<span style="color:#FF0000;">android:listSelector="@drawable/item_selector"</span> //对颜色的改变的调用。
/>
</LinearLayout>
2.在drawable中添加一个item_selector.xml文件,用于供listview调用。
3.在listview中进行对点击时背景改变时调用。
colors.xml文件:<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#00000000</color>// 透明的 当默认的时候也就是不进行点击事件的时候进行调用。
<color name="choose">#9fb01513</color>//当点击时需要显示的颜色。
</resources>
item_selector.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
//默认不被按压的状态
<item android:drawable="@color/transparent" android:state_pressed="false"/>
//按钮被按压下的状态
<item android:drawable="@color/choose" android:state_pressed="true"/>
</selector>在listview中设置的值:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lv_show"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<span style="color:#FF0000;">android:listSelector="@drawable/item_selector"</span> //对颜色的改变的调用。
/>
</LinearLayout>
相关文章推荐
- Android例listview中android:descendantFocusability用法简析
- MTK Android Driver知识大全
- Android控件动画
- at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:)
- Android Security Model
- Android SDK Manager
- 使用html写一个android关于界面,事情原来可以如此简单
- 【Android】Fragment真正意义上的onResume和onPause
- Android内的生命周期整理
- Android数据库(八)之使用LitePal聚合函数
- Eclipse Android项目 为控件添加了Id,但是在Java代码中提示xxx cannot be resolved or is not a field
- Android数据库(七)之LitePal查询艺术
- Android Studio创建项目
- Android数据库(六)之LitePal的修改和删除
- Android数据库(五)之LitePal的存储操作
- Android数据库(四)之使用LitePal建立关联表
- Android的Style的使用
- Android数据库(三)之使用LitePal升级表
- Android之自定义标题
- Android数据库(二)之创建表和LitePal的基本用法