当前位置: 首页 > 编程笔记 >

Android编程之selector下设置背景属性值的方法

司空通
2023-03-14
本文向大家介绍Android编程之selector下设置背景属性值的方法,包括了Android编程之selector下设置背景属性值的方法的使用技巧和注意事项,需要的朋友参考一下

本文实例讲述了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开发相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程

希望本文所述对大家Android程序设计有所帮助。

 类似资料:
  • 本文向大家介绍Android编程中TextView字体属性设置方法(大小、字体、下划线、背景色),包括了Android编程中TextView字体属性设置方法(大小、字体、下划线、背景色)的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Android编程中TextView字体属性设置方法(大小、字体、下划线、背景色)。分享给大家供大家参考,具体如下: 希望本文所述对大家Android程序设计

  • 本文向大家介绍Android编程中selector背景选择器用法实例分析,包括了Android编程中selector背景选择器用法实例分析的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Android编程中selector背景选择器用法。分享给大家供大家参考,具体如下: 在Android开发过程中,经常对某一View的背景在不同的状态下,设置不同的背景,增强用户体验。如果按钮,在按下时,背

  • 本文向大家介绍Android编程之书架效果背景图处理方法,包括了Android编程之书架效果背景图处理方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Android编程之书架效果背景图处理方法。分享给大家供大家参考,具体如下: 在android应用中,做一个小说阅读器是很多人的想法,大家一般都是把如何读取大文件,如果在滚动或是翻页时,让用户感觉不到做为重点。我也在做一个类似一功能,可是

  • 问题内容: 设置背景: 是最好的方法吗? 问题答案: ;是正确的。 实现它的另一种方法是使用以下方法: 但我认为出现此问题是因为你尝试加载大图像。 这是一个很好的教程,介绍如何加载大位图。 更新: API级别22中不推荐使用getDrawable(int) 现在API级别22中不推荐使用。你应该改用支持库中的以下代码: 如果你引用的源代码,它将为你提供以下信息: 有关ContextCompat的更

  • 问题内容: 我在一个变量中有一个图像URL,我正在尝试使用jQuery将其设置为CSS样式: 这似乎不起作用,因为: 返回。 任何想法,我在做什么错? 问题答案: 您可能希望这样做(使其像普通的CSS背景图像声明一样):

  • 本文向大家介绍Android编程实现设置按钮背景透明与半透明及图片背景透明的方法,包括了Android编程实现设置按钮背景透明与半透明及图片背景透明的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Android编程实现设置按钮背景透明与半透明及图片背景透明的方法。分享给大家供大家参考,具体如下: Button或者ImageButton的背景设为透明或者半透明: 半透明 透明 颜色和不