ListView Item 选中时 改变 TextView 的字体颜色
2011-07-15 14:31
561 查看
在国内网上找了半天也没找到解决方案,还是stackoverflow给你,我是参考一些自己试试了,不用重写adapter来改变 TextView的字体颜色
文件名:list_item_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/green" /> <!-- focused -->
<item android:state_pressed="true" android:color="@color/green" /> <!-- pressed -->
<item android:state_selected="true" android:color="@color/green" /> <!-- pressed -->
<item android:color="@color/red" /> <!-- default -->
</selector>
文件名:list_item.xml
<?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="50dp">
<TextView
android:id="@+id/listItem_TV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@drawable/list_item_selector"
/>
</LinearLayout>
文件名:list_item_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/green" /> <!-- focused -->
<item android:state_pressed="true" android:color="@color/green" /> <!-- pressed -->
<item android:state_selected="true" android:color="@color/green" /> <!-- pressed -->
<item android:color="@color/red" /> <!-- default -->
</selector>
文件名:list_item.xml
<?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="50dp">
<TextView
android:id="@+id/listItem_TV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@drawable/list_item_selector"
/>
</LinearLayout>
相关文章推荐
- Android的ListView子Item选中改变TextView字体颜色
- UIPickerView控件中自定义 及 改变当前选中的Item的字体颜色
- ListView中TextView和item背景点击改变颜色
- listview选中时如何修改textview字体的颜色
- 改变TextView中部分字体颜色
- Android改变ListView选中行字体颜色
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 改变TextView部分字体的大小和颜色
- Android textview 同时改变字符串中部分字体的颜色与大小
- Android动态改变TextView字体颜色
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- textView改变字体颜色及换行
- Android TextView设置部分字体颜色改变,部分字体背景改变
- 改变textview字体颜色
- listview、GridView单点击效果,点击改变背景改变item字体颜色实现
- 改变textView之中任意字体的大小、粗细、颜色
- Android 点击ListView(或GridView)的一个item,使其里面textview变色,点击另一个这个恢复原来颜色
- Android动态改变TextView字体颜色
- 利用 SpannableStringBuilder 改变textview中字体的颜色
- textview字体颜色改变状态选择器