在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 -->
<item android:drawable="@drawable/button_normal"/><!-- default -->
</selector>
分享到:
相关推荐
Flutter的file_selector插件可以帮助开发者在移动应用中方便地选择文件。 要使用file_selector插件,首先需要将插件的依赖项添加到pubspec.yaml文件中,并运行flutter pub get命令获取插件的最新版本。 在插件使用...
Android selector 完整demo
浅谈android的selector背景选择器
Android studio非常实用的插件
探索Android中selector和shape的结合使用
Android应用源码开发Demo,主要用于毕业设计学习。
我们在做很多项目时,常常遇到同时选择多张图片的问题,我也很好奇,我在网上找了一个例子,放在这供大家下载,希望和大家交流学习
:joystick_selector: 这是游戏开发学习的资料库 :video_game: :joystick_selector: 第一步:游戏开发 :alien_monster: 游戏设计文件(GDD) 原型提示 发展历程 测试 验证方式 :joystick_selector: 第二步:专业...
一个强大的selector注入器,它可以让view自动产生selector状态,免去了你写selector的麻烦。
适用于Android的颜色选择器,由ProductiveMinds提供 适用于Android的实用颜色选择器插件
iOS和Android运行附带的-YouTube帧率更高! 什么键盘!? 很高兴你问 :grinning_face_with_sweat: ! :keyboard_selector: 移动键盘充其量是一种妥协。 通过在其顶部附加工具栏,使它们更易于使用。 :goal_net: ...
多模块依赖设置:Android + Kotlin + Gradle Kotlin DSL + Jacoco + SonarQube + buildSrc =:red_heart_selector:
Android 选择多张相册照片 可以设置选择日期 是否显示拍照功能 选择相片张数等功能 Android 选择多张相册照片 可以设置选择日期 是否显示拍照功能 选择相片张数等功能
http://blog.csdn.net/zhufuing/article/details/20134255博客的demo下载
:airplane_selector: 颤振离线 一个整洁的实用程序,可像老板一样处理离线/在线连接。 它提供对iOS和Android平台(offcourse)的支持。 :military_medal: 正在安装 dependencies : flutter_offline : " ^0.3.0 " ...
学习X清华大学网络学堂App,以React Native构建使用React Native开发的清华大学网络学习应用程序 :atom_symbol_selector:下载Android替代品iOS替代品macOS替代品应用功能基本的浏览老师发布的最新通知。 预览或下载...
Android自定义矩形及selector、shape的使用Android自定义矩形及selector、shape的使用
xrepo::card_index_dividers_selector:基于Xmake的跨平台CC ++软件包管理器
MaterialPreference::gear_selector:一个库,旨在用一些漂亮的东西替换Android框架上的默认首选项
Android-SpeedyViewSelector This is a change Background Or TextColor Selector support library, with which you can directly specify the Background to be displayed in different states or TextColor Layout...