`
zhouxiaoli521
  • 浏览: 566600 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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 -->
    <item android:drawable="@drawable/button_normal"/><!-- default -->
</selector>


http://androidit.diandian.com/post/84c5ade0-e5af-11e0-8458-782bcb38253b

 

分享到:
评论

相关推荐

    浅谈android的selector背景选择器

    `Selector`作为Android中一个非常重要的机制,允许开发者根据控件的不同状态来动态更改其背景图像或颜色等属性。本文将详细介绍`Selector`的基本概念、工作原理以及如何在ListView和Button等常见控件中应用这一机制...

    android-selector-chapek-master

    5. **版本兼容性检查**:在创建或修改选择器时,插件可能会检查所使用的属性是否适用于目标 Android API 版本,确保应用的向下兼容性。 6. **代码格式化**:为了保持代码整洁和统一,插件可能会提供一键格式化 XML ...

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

    在本篇文章中,我们将深入探讨如何在Android编程中使用Selector来设置背景属性值。 首先,创建Selector资源文件。在`res/drawable`目录下,新建一个XML文件,例如命名为`my_background_selector.xml`。这个文件会...

    Android selector背景选择器的使用详解

    在Android开发中,Selector是一种非常重要的资源类型,它允许我们为UI组件(如按钮、列表项等)定义不同状态下的背景或颜色。本篇文章将深入探讨Android中的Selector背景选择器的使用方法。 首先,让我们了解...

    Android中XML属性与解析

    - `android:orientation`:用于指定布局的方向,可选值为`horizontal`(水平)或`vertical`(垂直)。 ##### 2. RelativeLayout(相对布局) 相对布局允许控件基于其他控件或父容器的位置进行定位,提供了更高的...

    Android -- Time-Selector日期选择控件.zip

    `Time-Selector`是一个自定义的日期选择控件,它基于Android原生的`TimePicker`组件进行优化,提供了更加美观和用户友好的交互方式。本项目的目标是为开发者提供一个易于使用、功能丰富的日期和时间选择解决方案。 ...

    Android中的Selector的用法详解及实例

    这些属性值可以叠加使用,例如: ```xml &lt;item android:state_window_focused="true" android:state_pressed="true" android:drawable="@drawable/bg_selected"&gt; ``` 上面的配置表示非触摸模式下获得焦点并单击时...

    ListView Button ImageView 里应用selector选择器切换图片并保持住

    Selector是Android中的一个资源类型,它可以定义不同状态下的显示样式,如按下、聚焦、默认等状态。通常,selector包含两种或更多的状态,每种状态对应一个图片或颜色值。在XML文件中定义selector,我们可以使用`...

    Android通过textview设置状态

    在布局XML文件中,将TextView的`android:background`属性设置为刚刚创建的Selector资源。例如: ```xml android:id="@+id/myTextView" android:layout_width="wrap_content" android:layout_height="wrap_...

    Android中多图片选择器MultiImageSelector的使用(仿微信)

    -- 更多自定义属性 --&gt; ``` 在Activity中设置主题: ```java setTheme(R.style.AppTheme_MultiImageSelector); ``` 通过以上步骤,你就可以在你的Android应用中实现类似微信的多图片选择功能了。`...

    Android中使用Shape自定义形状

    - **多边形**:使用`&lt;polygon&gt;`,通过`android:points`属性定义顶点坐标,例如`"0,0 100,0 50,100"`。 4. **动态应用Shape** 将Shape定义为XML资源文件后,可以在布局文件中引用,作为View的背景: ```xml ...

    Android-使用ShapeInject可能很方便给View和ViewGroup设置背景不用再写selector文件啦

    在Android开发中,我们经常需要为View和ViewGroup设置各种形状和颜色的背景,这通常涉及到XML selector文件的编写,以便实现不同的状态(如按下、焦点等)下的不同背景效果。然而,这样的方式可能会使代码变得冗长且...

    Android shape和selector 结合使用实例代码

    1. `android:shape`:指定形状类型,可选值有`rectangle`(矩形)、`oval`(椭圆)、`line`(水平直线)和`ring`(环形)。 2. `&lt;gradient&gt;`:用于设置渐变效果。`android:startColor`和`android:endColor`分别定义...

    【android】listview改变选中行背景图片

    将该属性值设置为一个drawable资源。例如: ```xml android:id="@+id/listTV" android:layout_width="349px" android:layout_height="fill_parent" android:layout_marginLeft="26px" android:layout_...

    android中sharp的使用分享.pdf

    若要将边框设置为虚线,可以添加 `android:dashWidth` 和 `android:dashGap` 属性: ```xml android:width="2dp" android:color="#dcdcdc" android:dashWidth="5dp" android:dashGap="3dp" /&gt; ``` 4. **...

    android shape

    Android 中的 Shape 是一个非常重要的概念,它用于定义控件的显示属性,如颜色、渐变、描边、圆角、间隔等。今天,我们将详细地介绍 Shape 的使用方法和相关知识点。 首先,看下面的代码: ```xml &lt;!-- 实心 --&gt; ...

    Android 颜色16进制对应的xml配置值

    本篇文章将深入探讨16进制颜色与Android XML配置值之间的转换,以及如何在Android项目中有效地使用这些颜色资源。 首先,16进制颜色代码通常以"#"开头,后跟6位字符,分别代表红、绿、蓝三个颜色通道的值。例如,#...

    Android XML attribute

    为了帮助开发者更好地理解Android中的各种XML属性及其用途,本文将详细介绍部分核心XML元素及其属性,包括但不限于`&lt;animated-rotate&gt;`、`&lt;animation-list&gt;`、`&lt;bitmap&gt;`等。 #### `&lt;animated-rotate&gt;`: 动态旋转...

    Android Tablayout 自定义Tab布局的使用案例

    该属性有两个值:`fixed` 和 `scrollable`。`fixed` 模式下,Tab 将 fixed 在屏幕上,不允许滚动;`scrollable` 模式下,Tab 将可以滚动,用户可以通过滑动来选择不同的 Tab。 五、setCustomView() 设置自定义的 ...

    Android点击改变按钮颜色的3种效果

    然后在按钮的`android:background`属性中引用这个selector资源。 2. 动态改变背景色 在按钮的点击监听事件中,可以通过Java代码动态改变按钮的背景颜色。首先,在Java代码中获取按钮对象,然后在`...

Global site tag (gtag.js) - Google Analytics