目标:当item选中时,改变其背景图片。效果图如下:

直接在listview的xml文件中使用listselector:

1
2
3
4
5
6
7
8
9
<ListView
    android:id="@+id/listTV"
    android:layout_width="349px"
    android:layout_height="fill_parent"
    android:layout_marginLeft="26px"
    android:layout_marginTop="20px"
    android:listSelector="@drawable/tvitembg"
    android:focusable="true">
</ListView>

然后另外定义,tvitembg.xml文件定义其背景图片:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- 没有焦点时的背景图片 -->
<!-- 
<item
    android:state_window_focused="false"/> 
-->
<!-- 非触摸模式下获得焦点并单击时的背景图片 --> 
<item
    android:state_focused="true"
    android:state_pressed="true"
    android:drawable= "@drawable/bg"/> 
<!-- 触摸模式下单击时的背景图片 -->
<!--
  <item
    android:state_focused="false"
    android:state_pressed="true"  
    android:drawable="@drawable/pic3" />
-->
<!--选中时的图片背景  --> 
<item
    android:state_selected="true"
    android:drawable="@drawable/bg"/>
<!--获得焦点时的图片背景  --> 
<item
    android:state_focused="true"
    android:drawable="@drawable/bg"/>
</selector>

这样就OK啦~~

【android】listview改变选中行背景图片的更多相关文章

  1. listview改变选中行字体颜色

    [android]listview改变选中行字体颜色 目标:选中item,其字体设置为#3197FF,未选中的,其字体为#FFFFFF 与listvew设置选中行item背景图片一样,使用select ...

  2. WPF DataGrid ListView 等等 改变 选中行 颜色;以及 不变的原因

    WPF中改变选中行的颜色是很简单的,就是用触发器:比如:以DataGrid为例: DataGrid.RowStyle Style TargetType= DataGridRow SetterPrope ...

  3. [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络)

    [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络) 地址: http://www.eoeandroid.com/thread-918356-1-1.html h ...

  4. 【转】UGUI之用脚本动态的改变Button的背景图片 和 颜色

    http://blog.csdn.net/u014771617/article/details/45102701 public Button button;void Start(){ColorBloc ...

  5. Android ListView分页加载时图片显示问题

    场景:Android ListView需要分页加载,每个item中会有图片,图片又是从网络下载的. 问题:在滑动加载下一页时,上一页的图片明明已经下载完成了,但是无法显示出来. Bug重现: 1,加载 ...

  6. 安卓工作室android studio 美化 ,设置背景图片。

    作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313134555 @qq.com sexy Editor 点击file-> ...

  7. DEV GridControl.TableView FocusedRow选中行背景颜色

    上次修改了TableView.RowStyle,导致了一个问题:覆盖了GridControl默认的选中行颜色. 于是需要重写选中行的颜色. 刚开始的想法是: <dxg:TableView> ...

  8. 【WPF】通过修改dataGrid的cell的style,改变选中行失去焦点时的颜色

    <Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <Trigger Proper ...

  9. android listview的HeadView左右切换图片(仿新浪,网易,百度等切换图片)

    首先我们还是看一些示例:(网易,新浪,百度) 显示效果都不错,可是手感就不一样了,百度最棒,网易还行,新浪就操作很不好,这里我说的是滑动切换图片.自己可以测试一下.不得不说牛叉的公司确实有哦牛叉的道理 ...

随机推荐

  1. [BZOJ1072][SCOI2007]排列perm 状压dp

    1072: [SCOI2007]排列perm Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2488  Solved: 1546[Submit][St ...

  2. 微信小程序 使用swiper制作一个滑动导航

    最近在做一个导航的时候,发现使用overflow-x: auto来做多内容滑动导航效果很不好,思索是不是可以使用swiper来做一个,研究了下其实发现原理基本相同 这里说下,要用swiper做导航菜单 ...

  3. POJ 2923 【01背包+状态压缩/状压DP】

    题目链接 Emma and Eric are moving to their new house they bought after returning from their honeymoon. F ...

  4. HDU 6113 度度熊的01世界【DFS/Flood Fill】

    度度熊的01世界 Accepts: 967 Submissions: 3064 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...

  5. Activator常用方法

    1.获取图片 public static Image getImage(String key) {        Image img = getDefault().getImageRegistry() ...

  6. Python的并发并行[3] -> 进程[1] -> 多进程的基本使用

    多进程的基本使用 1 subprocess 常用函数示例 首先定义一个子进程调用的程序,用于打印一个输出语句,并获取命令行参数 import sys print('Called_Function.py ...

  7. 对事务的特性ACID的理解

    对事务的特性ACID的理解 数据库的事务必须具备ACID特性,ACID是指 Atomicity(原子性).Consistensy(一致性).Isolation(隔离型)和Durability(持久性) ...

  8. luogu P1417 烹调方案

    题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...

  9. manacher(马拉车)算法详解+例题一道【bzoj3790】【神奇项链】

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=39091399 (CSDN好像有bug,不知道为什 ...

  10. Ubuntu 16.04服务器版查看IP、网关、DNS(非DHCP)

    查看IP ifconfig em1 Link encap:Ethernet HWaddr F0:1F:AF:D6:17:DD inet addr:115.238.54.116 Bcast:115.23 ...