zoukankan      html  css  js  c++  java
  • Android Resources ---color about text

    Note:If you want to provide a static color resource,use a simple color value.

    In Java: R.color.filename
    In XML: @[package:]color/filenameSYNTAX:

    <?xml version="1.0" encoding="utf-8"?>
    <selectorxmlns: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>

    1>selector:颜色源文件的根元素
    2>item:定义某一特定状态下的颜色属性包括”state“和color

    state:
    android:state_pressed 是否按下
    android:state_focused 是否取得焦点
    android:state_selected 是否被选择
    android:state_checkabled 组件是否能被check
    android:state_checked 被check了//
    android:state_enabled 能够接受触摸或者接触事件
    android:state_window_focused 应用程序是否在前台

    注:对于不同状态的item,程序会自上而下的匹配,最先匹配的得到程序

    XML file saved at res/color/button_text.xml:
    <?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>
    
    

    This layout XML will apply the color list to a View:

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

    注:同样的方法可以设置View的背景,以drawable Resource代替color Resource也可行。




  • 相关阅读:
    Java_适配器模式
    linux常用命令整理
    (转)使用隐藏的iframe 隐藏form提交,仿AJax无刷新提交,可以实现无刷新上传文件
    mysql添加并返回主键
    学习RMI
    关于bcprov-jdk16
    JavaScript在页面中的引用方法
    通过CFX发布WebService(一)
    字符串和json数据的转换
    MD5 加密与解密
  • 原文地址:https://www.cnblogs.com/LVAnny/p/I_WANT_PROVIDE_A_STATIC_COLOR_RESOURCE.html
Copyright © 2011-2022 走看看