导航:首页 > 操作系统 > androidlistview点击背景

androidlistview点击背景

发布时间:2023-03-23 07:42:08

android listview点击背景改变,点击其他事背景变回原来的样子,被点击的改变

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android ">手隐握
<item android:state_window_focused="false"
android:drawable="@drawable/没有焦点时的图片背景" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable=
"@drawable/非触摸模式下获得焦点并单击时的背景图片" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/触摸模式下单击时的背景图片" />
<item android:state_selected="true"
android:drawable="@drawable/选中时的图片背景" />毕庆
<item android:state_focused="true"
android:drawable="@drawable/获得焦点时的图片背景" />
</selector>

在ListView布局携败中设置android:listSelector。。。。

Ⅱ 实现android中listView的item点击变背景色

我的错没看清楚裤岩问渗销题。
按题主代码自测在4.4.2上面没有出现该问题。
---------------------原答案分隔线------------------------
你这样写的代码胡喊御不是最优的,一种比较好的写法是自定义Adapter,在getview方法里面自定义一个list的item的xml文件,在xml里面用自定义selector。而listview在xml里面的属性中listSelector要设置为空就是android:listSelector="@null"

Ⅲ android listView 怎么指定项的背景设置

android listview指定项设定背景步骤如下:

  1. 监听列表项监听事件,取得被点击的view,设置为:view.setSelector("true");

2.在适配器塌镇中,用if-else语句,判断选择的列表项设置背景,没有选中的则默认背景,代码如下:


java">try{
if(selectItem==position){
messagetitle.setTextColor(android.graphics.Color.BLACK);
messagetime.setTextColor(android.graphics.Color.BLACK);
viewHolder.messagetitle.setText(maps.get(position)
.get("messagetitle").toString());
viewHolder.messagetime.setText(maps.get(position)
.get("messagetime").toString());
convertView.findViewById(R.id.expandable1)
.setBackgroundColor(android.graphics.Color.WHITE);
convertView.findViewById(R.id.expandable1)
.setBackgroundResource(R.drawable.menu_shapeclick);
}else{
messagetitle.setTextColor(android.graphics.Color.WHITE);
messagetime.setTextColor(android.graphics.Color.WHITE);
viewHolder.messagetitle.setText(maps.get(position)
.get("messagetitle").toString());
viewHolder.messagetime.setText(maps.get(position)
孙闹.get("messagetime").toString());
convertView.findViewById(R.id.expandable1)
.setBackgroundResource(
团凯粗R.drawable.menu_shapeunonclick);
}
}catch(Exceptionex){
ex.printStackTrace();
}
returnconvertView;
阅读全文

与androidlistview点击背景相关的资料

热点内容
当程序员遇到产品 浏览:976
己亥pdf 浏览:860
jpg格式怎么改成文件夹 浏览:576
用window编程plc 浏览:92
程序员到阿里技术总监之路 浏览:410
怎么把pdf合在一起 浏览:368
直线命令英语 浏览:110
编译系统程序在主存储器里吗 浏览:903
java开发工作经验 浏览:791
群英服务器如何 浏览:484
php获取不到cookie 浏览:847
备案云服务器类型 浏览:993
mc服务器怎么清空经验指令 浏览:409
拿到服务器后如何识别是否是蜜罐 浏览:770
现在学单片机还有未来吗 浏览:885
程序员电力 浏览:373
程序员一定要大专吗 浏览:334
加密门禁读取软件 浏览:773
编译二进制有用吗 浏览:438
程序员的必备电脑配置 浏览:839