ListView未选中时背景

想给ListView设置未选中时背景,结果发现需要同时在ListView中设置listSelector和在ListView的单项item的布局文件中设置background,原因来日再查,知情者可以留言,谢谢。

ListView项的布局代码如下:

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/search_layout"
        android:layout_marginBottom="0dp"
        android:layout_marginTop="15dp"
        android:cacheColorHint="@android:color/transparent"
        android:listSelector="@drawable/list_item_range_all_selector_with_outline
    </ListView>

单项item的部分布局文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/app_list_layout"
    android:layout_width="match_parent"
    android:layout_height="90dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="4dp"
    android:descendantFocusability="blocksDescendants"
    android:background="@drawable/list_item_range_all_selector_with_outline">

list_item_range_all_selector_with_outline的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/range_bg_all" android:state_pressed="true"/>
    <item android:drawable="@drawable/list_bg"/>

</selector>

而list_bg是个点9图片,如下:

注意list_item_range_all_selector_with_outline,在两个文件上都要设置上,才能得到以下效果:

1、未选中时效果,背景图为list_bg.9.png

2、按住某一项时效果

如果只在ListView中设置了,那会出现以下情况:

而如果仅在单项item布局中设置了background,会出现以下情况:

时间: 2024-08-10 04:30:49

ListView未选中时背景的相关文章

listview更改选中时item背景色(转)

默认情况下使用ListView背景色是黑色,选中item的高亮颜色是菊黄色,很多时候不得不自己定义背景色或者背景图 android:cacheColorHint="@android:color/transparent",意思为去黑色底色,比如ListView滚动时会刷新界面,默认颜色还是系统颜色,所以采用这种方式设置其为透明即可,这个属性在ListView中使用圆角图片来设置ListView时很有用 android:divider="@null"用于去掉listvi

Android美工坊--listview更改选中时item背景色

默认情况下使用ListView背景色是黑色,选中item的高亮颜色是菊黄色,很多时候不得不自己定义背景色或者背景图 android:cacheColorHint="@android:color/transparent",意思为去黑色底色,比如ListView滚动时会刷新界面,默认颜色还是系统颜色,所以采用这种方式设置其为透明即可,这个属性在ListView中使用圆角图片来设置ListView时很有用 android:divider="@null"用于去掉listvi

UItableViewCell选中时的颜色及tableviewCell的select和deselect

今天做项目美工和我说cell点击后再跳回当前页面cell的默认点击状态应该取消,后来在网上查到,其实比较简单,有两种实现方法,代码如下 方法一: 在页面将要出现的时候对tableview执行deselect操作 - (void)viewWillAppear:(BOOL)animated{ [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES]; } 看上面的英文也应

UITableViewCell的选中时的颜色及tableViewCell的selecte与deselecte

    1.系统默认的颜色设置 [cpp] viewplaincopy //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = UITableViewCellSelectionStyleBlue; //灰色 cell.selectionStyle = UITableViewCellSelectionStyleGray; 2.自定义颜色和背景设置 改变UITableViewCe

iOS开发UITableViewCell的选中时的颜色设置

1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = UITableViewCellSelectionStyleBlue; //灰色 cell.selectionStyle = UITableViewCellSelectionStyleGray; 2.自定义颜色和背景设置 改变UITableViewCell选中时背景色: UIColor *color

UITableViewCell的选中时的颜色设置

[cpp] view plaincopy 1.系统默认的颜色设置 [cpp] view plaincopy //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = UITableViewCellSelectionStyleBlue; //灰色 cell.selectionStyle = UITableViewCellSelectionStyleGray; 2.自定义颜色和背景

设置UITableViewCell 选中时的背景颜色

自定义Cell如图 一个View上面放了四个Label 分别连线到.m文件中 @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UILabel *positionLabel; @property (weak, nonatomic) IBOutlet UILabel *paperLabel; @property (weak, nonatomic) IBOutle

改变listview中item选中时文字的颜色

当listview的某个item选中时,默认有个选中的高亮显示,如果你要自定义选中时的高亮显示效果,可以在listview中设置属性 1 android:listSelector="@drawable/item_selector" 其中item_selector是在drawable目录下定义的一个xml文件,这种用于突出不同状态下显示效果的xml文件我们称之为selector: 1 2 3 4 5 6 7 <?xml version="1.0" encodin

cell添加选中时的背景图片、显示图片和图片自适应框的大小

1.给cell添加选中时的背景图片 UIView *myview = [[UIView alloc] init]; myview.frame = CGRectMake(0, 0, 320, 47); myview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"0006.png"]]; cell.selectedBackgroundView = myview; 2.显示图片 CGRect my