ListView 点击Item的时候,改变文字颜色和背景色
来源:互联网 发布:淘宝影响二次销售举证 编辑:程序博客网 时间:2024/05/17 09:14
分类: Android 2012-07-05 06:51 516人阅读 评论(0)收藏举报
listviewandroidlayoutencodingobjectstring
代码
list.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical"
- >
- <ListView
- android:id="@+id/list"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /></LinearLayout>
list_item.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical"
- android:background="@drawable/item_type" <!-- item背景色变换 -->
- >
- <TextView
- android:id="@+id/txt"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- android:layout_margin="5dp"
- android:textColor="@drawable/item_selector" <!-- item文字颜色变换 -->
- />
- </LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/item_type" <!-- item背景色变换 --> > <TextView android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:layout_margin="5dp" android:textColor="@drawable/item_selector" <!-- item文字颜色变换 --> /></LinearLayout>
再写一个selector用来做颜色变换
- <?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/text_type02" /> <!-- focused -->
- <item android:state_pressed="true" android:color="@color/text_type02" /> <!-- pressed -->
- <item android:state_selected="true" android:color="@color/text_type02" /> <!-- pressed -->
- <item android:color="@color/text_type01" /> <!-- default -->
- </selector>
<?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/text_type02" /> <!-- focused --> <item android:state_pressed="true" android:color="@color/text_type02" /> <!-- pressed --> <item android:state_selected="true" android:color="@color/text_type02" /> <!-- pressed --> <item android:color="@color/text_type01" /> <!-- default --></selector>
然后到activity中
- list = (ListView) findViewById(R.id.list);
- data = new ArrayList<HashMap<String, Object>>();
- for(int i=0; i<5; i++) {
- map = new HashMap<String, Object>();
- map.put("data", "Test" + i);
- data.add(map);
- }
- SimpleAdapter simple = new SimpleAdapter(this, data, R.layout.list_item, new String[]{"data"},new int[]{R.id.txt});
- list.setAdapter(simple);
list = (ListView) findViewById(R.id.list); data = new ArrayList<HashMap<String, Object>>(); for(int i=0; i<5; i++) { map = new HashMap<String, Object>(); map.put("data", "Test" + i); data.add(map); } SimpleAdapter simple = new SimpleAdapter(this, data, R.layout.list_item, new String[]{"data"},new int[]{R.id.txt}); list.setAdapter(simple);这样就可以实现效果了。
不使用系统的,尽量自定义
使用系统的试过几个不知道哪里不对,一直没生效,这样写就可以了。
- ListView 点击Item的时候,改变文字颜色和背景色
- ListView 点击Item的时候,改变文字颜色和背景色
- ListView 点击Item的时候,改变文字颜色和背景色
- android listView 点击Item的时候,改变文字颜色和背景色
- Android ListView 点击Item的时候,改变文字颜色和背景色
- AndroidListView点击Item的时候 改变文字颜色和背景色
- 点击listview的时候listitem不改变背景色
- 解决: 用代码改变listview的item背景色时,点击一个item,每隔几个item背景色重复
- 点击listviewItem后,改变当前Item背景色和字体颜色,其他不变
- Android ListView的item背景色设置和item点击无响应的解决方法
- 自定义ListView的点击Item项后进入另一个activity背景色改变在pressed或selected等状态时的颜色
- ListView中点击改变背景色并且原来的恢复到原来的颜色
- MFC EDIT控件中改变背景色和文字颜色
- MFC EDIT控件中改变背景色和文字颜色
- 如何改变下拉菜单中文字颜色和背景色
- SecureCRT中改变背景色和文字颜色
- MFC EDIT控件中改变背景色和文字颜色
- SecureCRT中改变背景色和文字颜色
- 网络七层协议
- 初扫css笔记-1
- PermGen space错误解决方法
- Real-Time Tracking and Tuning for Busy Tomcat Servers
- 由于应用程序配置不正确, 应用程序未能启动. 重新安装应用程序可能会纠正这个问题.
- ListView 点击Item的时候,改变文字颜色和背景色
- HEVC学习(一) —— HM的使用
- (转)Android Activity 常用功能设置(全屏、横竖屏、持续亮屏等)
- 第七章——DMVs和DMFs(1)
- swfupload chrome 22.0.XXXXX dev版上传图片按钮点击无返应解决办法
- Android 应用开发技巧之模版修改
- Indexed Views in SQL Server
- 设计模式之中介者模式
- 资本循环