zoukankan      html  css  js  c++  java
  • StateListDrawable 资源

    StateListDrawable 用于组织多个 Drawable 对象。当使用 StateListDrawable 作为目标组件 的背景、前景图片时,StateListDrawable 对象所显示的  Drawable 对象会随目标组件状态的改 变而自动切换。
    定义 StateListDrawable 对象的 XML 文件的根元素为<selector.../>,该元素可以包含多个<item.../>元素,该元素可指定如下属性。 
    • android:color 或 android:drawable:指定颜色或 Drawable 对象。 
    • android:state_xxx:指定一个特定状态。 
    例如如下语法格式:
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 指定特定状态下的颜色 -->
    <item android:color="hex_color""
          android:state_pressed=["true" | "false"] />
    </selector>
     
     
    高亮显示正在输入的文本示例
     
    my_image.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 指定获得焦点时的颜色 -->
        <item android:state_focused="true"
            android:color="#f44"/>
        <!-- 指定失去焦点时的颜色 -->
        <item android:state_focused="false"
            android:color="#eee"/>
    </selector>
    main.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <!-- 使用StateListDrawable资源 -->
    <EditText  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textColor="@drawable/my_image"
        />
    <EditText  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textColor="@drawable/my_image"
        />
    </LinearLayout>
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    深度解析VC中的消息传递机制(上)
    DLL的远程注入技术
    一些游戏编程的书[转]
    [转]小小C的C++之歌
    Windows Server 2008无法使用arp命令添加静态MAC绑定
    如何调用未公开的API函数[转]
    IOCP中的socket错误和资源释放处理方法
    TinyXML应用例子
    微软C/C++ 编译器选项参考
    [摘录]这几本游戏编程书籍你看过吗?
  • 原文地址:https://www.cnblogs.com/AndyGe/p/3436878.html
Copyright © 2011-2022 走看看