安卓Selector

本文由PurpleSword(jzj1993)原创,转载请注明
原文网址 http://blog.csdn.net/jzj1993

安卓的按钮复选框等,在点击、选中等不同状态时,显示的图片不同。通常可以使用Selector进行定义(如res/drawable/button_selector.xml)

下面以按钮为例进行简要介绍

首先需要图像文件(分别为未按下和按下状态的图片资源):
    drawable/button_bg_normal.png
    drawable/button_bg_pressed.png

Selector的定义

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- pressed -->
    <item android:drawable="@drawable/bgcolor_translucent" android:state_pressed="true"/>
    <!-- default -->
    <item android:drawable="@drawable/bgcolor_transparent"/>
</selector>

Selector的应用

在View中应用

    <ImageButton
        android:id="@+id/main_bn_add"
        android:background="@drawable/button_selector" />

在ListView中应用于子控件

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/settings_listview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:cacheColorHint="@null"
    android:divider="#FFFFFF"
    android:dividerHeight="2dp"
    android:listSelector="@drawable/selector_setting_item"
    android:scrollingCache="true" >
</ListView>


Selector还可以这样定义

Selector用颜色填充

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- pressed -->
    <item android:state_pressed="true"><color android:color="#80000000" />
    </item>
    <!-- default -->
    <item><color android:color="#00000000" />
    </item>
</selector>

Selector用渐变形状填充

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape>
            <gradient android:startColor="#8600ff" />
            <stroke android:width="2dp" android:color="#000000" />
            <corners android:radius="5dp" />
            <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
        </shape>
    </item>
    
    <item android:state_focused="true">
        <shape>
            <gradient android:startColor="#eac100" />
            <stroke android:width="2dp" color="#ffffff" android:color="#333333" />
            <corners android:radius="8dp" />
            <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
        </shape>
    </item>
</selector>


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/242143.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

u-net语义分割_使用U-Net的语义分割

u-net语义分割Picture By Martei Macru On Unsplash图片由Martei Macru On Unsplash拍摄 Semantic segmentation is a computer vision problem where we try to assign a class to each pixel . Unlike the classic image classification task where only one class value is …

我国身家超过亿元的有多少人?

目前我国身家达到亿元以上的人数&#xff0c;从公开数据来看大概有13万人&#xff0c;但如果把那些统计不到的隐形亿万富翁计算在内&#xff0c;我认为至少有20万以上。公开资料显示目前我国亿万富翁人数达到133000人根据胡润2018财富报告显示&#xff0c;目前我国&#xff08;…

地理空间数据

摘要 (Summary) In this article, using Data Science and Python, I will show how different Clustering algorithms can be applied to Geospatial data in order to solve a Retail Rationalization business case.在本文中&#xff0c;我将使用数据科学和Python演示如何将…

安卓PopupWindow

本文由PurpleSword(jzj1993)原创&#xff0c;转载请注明原文网址 http://blog.csdn.net/jzj1993定义弹窗动画res/anim/scale_in.xml<?xml version"1.0" encoding"utf-8"?><set xmlns:android"http://schemas.android.com/apk/res/android&…

嵌入式系统分类及其应用场景_词嵌入及其应用简介

嵌入式系统分类及其应用场景Before I give you an introduction on Word Embeddings, take a look at the following examples and ask yourself what is common between them:在向您介绍Word Embeddings之前&#xff0c;请看一下以下示例并问问自己它们之间的共同点是什么&…

山东男子5个月刷信用卡1800次,被银行处理后他选择29次取款100元

虽然我国实行的是存款自愿&#xff0c;取款自由的储蓄政策&#xff0c;客户想怎么取款&#xff0c;在什么时候取&#xff0c;取多少钱&#xff0c;完全是客户的权利&#xff0c;只要客户的账户上有钱&#xff0c;哪怕他每次取一毛钱取个100次都是客户的权利。但是明明可以一次性…

安卓传感器 Sensor

本文由PurpleSword(jzj1993)原创&#xff0c;转载请注明原文网址 http://blog.csdn.net/jzj19931、获取系统服务private SensorManager sensorManager;sensorManager (SensorManager) getSystemService(SENSOR_SERVICE);2、检测是否有传感器private boolean checkSensor() {if …

深发银行为什么要更名为平安银行?

深圳发展银行之所以更名为平安银行&#xff0c;最直接的原因是平安银行收购了深圳发展银行&#xff0c;然后又以平安集团作为主体&#xff0c;以深圳发展银行的名义收购了平安银行&#xff0c;最后两个人合并之后统一命名为平安银行。深圳发展银行更名为平安银行&#xff0c;大…

高斯过程分类和高斯过程回归_高斯过程回归建模入门

高斯过程分类和高斯过程回归Gaussian processing (GP) is quite a useful technique that enables a non-parametric Bayesian approach to modeling. It has wide applicability in areas such as regression, classification, optimization, etc. The goal of this article i…

假如购买的期房不小心烂尾了,那银行贷款是否可以不还了?

如今房价一路高升&#xff0c;再加上开发商融资难度越来越大&#xff0c;现在很多人都开始打期房的主意。期房不论是对开发商还是对购房者来说都是双赢的&#xff0c;开发商可以以较低的融资成本维持楼盘的开发&#xff0c;提高财务杠杆&#xff0c;而购房者可以较低的价格买房…

SQLite基本语法

本文由PurpleSword(jzj1993)原创&#xff0c;转载请注明原文网址 http://blog.csdn.net/jzj1993--创建表CREATE TABLE IF NOT EXISTS table1(id INTEGER PRIMARY KEY, name text NOT NULL, age INTEGER);--删除表DROP TABLE IF EXISTS table1;--增INSERT INTO table1(id,name) …

在银行存款5000万,能办理一张50万额度的信用卡吗?

拥有一张大额信用卡是很多人梦寐以求的事情&#xff0c;大额信用卡不仅实用&#xff0c;在关键时刻可以把钱拿出来刷卡或者取现&#xff0c;这是一种非常方便的融资方式。然而大额信用卡并不是说谁想申请就可以申请下来&#xff0c;正常情况下&#xff0c;10万以上额度以上的信…

hotelling变换_基于Hotelling-T²的偏最小二乘(PLS)中的变量选择

hotelling变换背景 (Background) One of the most common challenges encountered in the modeling of spectroscopic data is to select a subset of variables (i.e. wavelengths) out of a large number of variables associated with the response variable. It is common …

商业银行为什么大量组织高净值小规模活动?

在管理界有一个非常著名的定律叫做二八定律&#xff0c;所谓28定律就是20%的客户贡献了企业80%的利润。虽然这个定律在银行不一定适用&#xff0c;但同样的道理用于银行营销也是合适的。银行之所以经常组织一些高净值小规模的活动&#xff0c;因为这些客户的资产和价值比较高&a…

Notepad++中用正则表达式匹配中文

通常正则表达式匹配中文可以利用Unicode的特点&#xff0c;使用[\u4e00-\u9fa5]匹配。但在Notepad中不能正常使用。 解决方法是&#xff0c;首先将编码转换成Unicode&#xff08;菜单->格式->转换为UTF-8&#xff0c;如果不转换可能匹配出错&#xff09;&#xff0c;然后…

在县城投资买一辆出租车,一个月能收入多少钱?

在县城投资出租车能赚多少钱具体要看你是什么县城&#xff0c;比如西部的县城勉强能养活自己&#xff0c;中部的县城一个月能赚个5、6千&#xff0c;东部的小县城月赚个万元以上也有可能。具体回报率怎么样可以先算下投资一个出租车的成本投资一个出租车的构成成本比较多&#…

通过ISO镜像文件安装Ubuntu(可实现默认启动Windows的双系统)

解压文件 使用WinRAR等软件&#xff0c;Ubuntu ISO镜像文件中的casper文件夹解压到硬盘中的任意分区根目录&#xff0c;把ISO镜像也放在那个分区根目录。 使用Grub4dos启动Ubuntu 使用grub4dos启动Ubuntu&#xff0c;menu.lst写法如下。其中root命令指定了硬盘分区编号&#xf…

命名实体识别 实体抽取_您的公司为什么要关心命名实体的识别

命名实体识别 实体抽取Named entity recognition is the task of categorizing text into entities, such as people, locations, and dates. For example, for the sentence, On April 30, 1789, George Washington was inaugurated as the first president of the United Sta…

表达式测试

1111 (parameters) -> { statements; }//求平方 (int a) -> {return a * a;}//打印&#xff0c;无返回值 (int a) -> {System.out.println("a " a);}