当前位置:操作系统 > 安卓/Android >>

Resource-type-->Color State List Resource

Color State List Resource
ColorStateList 可以用XML定义,并且可以用到View文字上。

 


文件存放位置:

 res/color/filename.xml

 

 

语法:


<?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"]
        android:state_focused=["true" | "false"]
        android:state_selected=["true" | "false"]
        android:state_checkable=["true" | "false"]
        android:state_checked=["true" | "false"]
        android:state_enabled=["true" | "false"]
        android:state_window_focused=["true" | "false"] />
</selector>例子:

定义,/res/color/button_text_color.xml


[java]
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" 
          android:color="#ffff0000"/> <!-- pressed --> 
    <item android:state_focused="true" 
          android:color="#ff0000ff"/> <!-- focused 在键盘手机上才会显示效果 -->  
    <item android:color="#ff000000"/> <!-- default --> 
</selector> 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- focused 在键盘手机上才会显示效果 -->
    <item android:color="#ff000000"/> <!-- default -->
</selector>
应用:


[html]
<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/button_text" 
    android:textColor="@color/button_text_color" /> 

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:textColor="@color/button_text_color" />

 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,