Android编程之selector下设置背景属性值的方法
作者:Leo Chin 发布时间:2023-08-23 08:07:49
本文实例讲述了Android编程之selector下设置背景属性值的方法。分享给大家供大家参考,具体如下:
在res/drawable文件夹新增一个文件,此文件设置了图片的触发状态,你可以设置 state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等几个状态:
android:state_pressed
Boolean. "true" if this item should be used when the object is pressed (such as when a button is touched/clicked); "false" if this item should be used in the default, non-pressed state.
如果是true,当被点击时显示该图片,如果是false没被按下时显示默认。
android:state_focused
Boolean. "true" if this item should be used when the object is focused (such as when a button is highlighted using the trackball/d-pad); "false" if this item should be used in the default, non-focused state.
true,获得焦点时显示;false,没获得焦点显示默认。
android:state_selected
Boolean. "true" if this item should be used when the object is selected (such as when a tab is opened); "false" if this item should be used when the object is not selected.
true,当被选择时显示该图片;false,当未被选择时显示该图片。
android:state_checkable
Boolean. "true" if this item should be used when the object is checkable; "false" if this item should be used when the object is not checkable. (Only useful if the object can transition between a checkable and non-checkable widget.)
true,当CheckBox能使用时显示该图片;false,当CheckBox不能使用时显示该图片。
android:state_checked
Boolean. "true" if this item should be used when the object is checked; "false" if it should be used when the object is un-checked.
true,当CheckBox选中时显示该图片;false,当CheckBox为选中时显示该图片。
android:state_enabled
Boolean. "true" if this item should be used when the object is enabled (capable of receiving touch/click events); "false" if it should be used when the object is disabled.
true,当该组件能使用时显示该图片;false,当该组件不能使用时显示该图片。
android:state_window_focused
Boolean. "true" if this item should be used when the application window has focus (the application is in the foreground), "false" if this item should be used when the application window does not have focus (for example, if the notification shade is pulled down or a dialog appears).
true,当此activity获得焦点在最前面时显示该图片;false,当没在最前面时显示该图片。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed"/><!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused"/><!-- focused -->
<itemandroid:drawable="@drawable/button_normal"/><!-- default -->
</selector>
希望本文所述对大家Android程序设计有所帮助。


猜你喜欢
- Java goto语句妙用今天和朋友聊天的时候,无意间聊到了 goto 语句,但是在 Java 中, goto 是保留关键字,但是朋友说 J
- @property可以将python定义的函数“当做”属性访问,从而提供更加友好访问方式,但是有时候setter/deleter也是需要的。
- 项目地址:gitee.com/baojh123/rp…netty-study 这个项目是没用到的,可以删掉,主要是测试
- 代码实例一 using System; using System.IO; using System.Collections; using S
- 这是进行Java Web开发必备的一个过程,仅供新手参考,高手可以忽略!JDK 和 JRE 的区别JRE(Java Runtime Envi
- 1.新建Android studio工程2.新建class:AppKey.java.主要为了保存密钥代码块package com...adm
- Step1: 安装JDK并配置环境变量;Step2: 安装Gradle进入点击打开链接官网首页点击install gra
- 目录前言准备工作Nacos安装及使用入门准备三个SpringBoot服务,引入Nacos及Kafka业务解读Nacos配置创建配置读取配置监
- Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件,由于手动书写很容易出错,我们可以利用Myba
- 本文实例为大家分享了java模拟斗地主发牌的具体代码,供大家参考,具体内容如下1.案例介绍规则:组装54张扑克牌54张牌顺序打乱三个玩家参与
- 本文实例分析了C#中使用资源的方法。分享给大家供大家参考。具体如下:这里总结一个在C#中如何使用资源的方法如下:方法一、使用本地文件1、将本
- 本文实例讲述了C#实现在前端网页弹出警告对话框(alert)的方法。分享给大家供大家参考。具体如下:通常我们通过JS生成警告对话框,下面的代
- 要求环境信息:WIN2008SERVER 开发工具:VS2015 开发语言:C#要求: 1.点击同步数据后接口获取数
- 本章节更加具体化的学习编译器还有哪些可以优化的方便,让你的应用展现出更好的性能。JIT编译器版本JIT编译器有不同的版本,而最终你使用哪种,
- 优麒麟Ubuntu20.04中使用VS Code。VS Code的版本是1.48.0。以下内容仅限于上述环境,对于Windows环境下的使用
- 关于在Android中实现ListView的弹性效果,有很多不同的方法,网上一搜,也有很多,下面贴出在项目中经常用到的两种实现ListVie
- mybatis oracle 自增序列的代码如下所示:<insert id=" insert " useGener
- 这个问题百度上一搜一大把,基本上都是说找到和SurfaceView的比例相近的camera预览尺寸,但是发现预览时候还是差了点意思,具体看下
- windows环境下1、输出logcat日志到本地文件adb logcat -> F:/logcat.txt2、输出带时间的logca
- 今天遇到一个需求对上传的图铺满水印,在网上找了半天都是在指定位置设置水印,下面代码是我通过在网上找的代码,然后改造而成的。我们先看一下效果图