AndroidListView点击Item的时候 改变文字颜色和背景色
来源:互联网 发布:php数据库输出乱码 编辑:程序博客网 时间:2024/04/28 15:08
效果图如下:
list.xml:
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
03.
android:layout_width=
"fill_parent"
04.
android:layout_height=
"wrap_content"
05.
android:orientation=
"vertical"
06.
android:background=
"#ffffff"
07.
android:paddingTop=
"10dp"
>
08.
09.
<TextView
10.
android:id=
"@+id/text"
11.
android:layout_width=
"fill_parent"
12.
android:layout_height=
"wrap_content"
13.
android:gravity=
"center"
14.
android:textSize=
"20sp"
/>
15.
16.
<View
17.
android:layout_width=
"match_parent"
18.
android:layout_height=
"1dp"
19.
android:layout_marginTop=
"10dp"
20.
android:background=
"#e6e6e6"
/>
21.
22.
<ListView
23.
android:id=
"@+id/list"
24.
android:layout_width=
"match_parent"
25.
android:layout_height=
"wrap_content"
>
26.
</ListView>
27.
28.
</LinearLayout>
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
03.
android:layout_width=
"fill_parent"
04.
android:layout_height=
"fill_parent"
05.
android:paddingLeft=
"20dp"
06.
android:paddingTop=
"10dp"
07.
android:paddingBottom=
"10dp"
08.
android:background=
"@drawable/listitem_selector"
>
09.
10.
<TextView
11.
android:id=
"@+id/text1"
12.
android:layout_width=
"wrap_content"
13.
android:layout_height=
"wrap_content"
14.
android:textColor=
"@drawable/font_selector"
15.
android:duplicateParentState=
"true"
16.
android:gravity=
"center_vertical"
17.
android:textSize=
"18sp"
/>
18.
19.
</LinearLayout>
listitem_selector:
01.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
02.
<selector xmlns:android=
"http://schemas.android.com/apk/res/android"
>
03.
04.
<!-- 没有焦点时的背景颜色 -->
05.
<item android:drawable=
"@color/unfocused"
android:state_window_focused=
"false"
/>
06.
<!-- 非触摸模式下获得焦点并单击时的背景颜色 -->
07.
<item android:drawable=
"@color/pressed"
android:state_focused=
"true"
android:state_pressed=
"true"
/>
08.
<!-- 触摸模式下单击时的背景颜色 -->
09.
<item android:drawable=
"@color/pressed"
android:state_focused=
"false"
android:state_pressed=
"true"
/>
10.
<!-- 选中时的背景颜色 -->
11.
<item android:drawable=
"@color/pressed"
android:state_selected=
"true"
/>
12.
<!-- 获得焦点时的背景 颜色 -->
13.
<item android:drawable=
"@color/pressed"
android:state_focused=
"true"
/>
14.
15.
</selector>
font_selector:
1.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
2.
<selector xmlns:android=
"http://schemas.android.com/apk/res/android"
>
3.
<item android:state_focused=
"true"
android:color=
"#ff0030"
/> <!-- focused -->
4.
<item android:state_pressed=
"true"
android:color=
"#ff0030"
/> <!-- pressed -->
5.
<item android:state_selected=
"true"
android:color=
"#ff0030"
/> <!-- pressed -->
6.
<item android:color=
"#222222"
/> <!--
default
-->
7.
</selector>
01.
listView = (ListView) contentView1.findViewById(R.id.list);
02.
ArrayList<HashMap<String, String>> data =
new
ArrayList<HashMap<String, String>>();
03.
for
(String i : name) {
04.
HashMap<String, String> map =
new
HashMap<String, String>();
05.
map.put(
"data"
, i);
06.
data.add(map);
07.
}
08.
SimpleAdapter simple =
new
SimpleAdapter(getActivity(), data,
09.
R.layout.layout_popup_item,
new
String[] {
"data"
},
10.
new
int
[] { R.id.text1 });
11.
listView.setAdapter(simple);
注意:
TextView 还要增加个属性
android:duplicateParentState="true"
这样才会跟随ParentView的状态来变化
3 0
- AndroidListView点击Item的时候 改变文字颜色和背景色
- ListView 点击Item的时候,改变文字颜色和背景色
- ListView 点击Item的时候,改变文字颜色和背景色
- ListView 点击Item的时候,改变文字颜色和背景色
- android listView 点击Item的时候,改变文字颜色和背景色
- Android ListView 点击Item的时候,改变文字颜色和背景色
- 点击listviewItem后,改变当前Item背景色和字体颜色,其他不变
- MFC EDIT控件中改变背景色和文字颜色
- MFC EDIT控件中改变背景色和文字颜色
- 如何改变下拉菜单中文字颜色和背景色
- SecureCRT中改变背景色和文字颜色
- MFC EDIT控件中改变背景色和文字颜色
- SecureCRT中改变背景色和文字颜色
- SecureCRT中改变背景色和文字颜色
- QT控制选中item的文字颜色(HighlightedText) 和 QT表格交替背景色
- QT控制选中item的文字颜色(HighlightedText) 和 QT表格交替背景色
- MFC List Control控件改变Item的颜色和背景色
- 点击listview的时候listitem不改变背景色
- PHP 左旋字符串的两种方法
- HDU 3999 The order of a Tree 二叉树
- spark中的action和transformation
- [IOS]对UITableView的简单封装,实现了下拉放大头部图片的效果
- jquery获取屏幕宽度的问题
- AndroidListView点击Item的时候 改变文字颜色和背景色
- POJ 3304 判断线段和直线相交
- android获得屏幕高度和宽度
- poj 3132 Sum of Different Primes(01背包)
- Merge into的注意点之ORA-30926
- clear:both 的妙用
- Linux 配置笔记
- 通州首家民营文化企业——点创世纪文化传播有限公司成功上市
- 自定义实现String类