zoukankan      html  css  js  c++  java
  • attrs.xmlz

    在res资源目录的values目录下创建一个attrs.xml的属性定义文件,并在该文件中通过如下代码定义相应的属性即可。

    属性名,属性格式
    <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="instruction"> <attr name="focusable" format="boolean" /> <attr name="layout_width" format="dimension" /> <attr name="pointX" format="float" /> <attr name="rightTextColor" format="color" /> <attr name="rightBackground" format="reference|color" />引用类型或者color型 <attr name="pointY" format="integer" /> <attr name="text" format="string" /> <attr name="pivotX" format="fraction" /> </declare-styleable> 枚举值 <declare-styleable name="enum"> <attr name="myEnum"> <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable> 位或运算 <declare-styleable name="flag"> <attr name="myFlag"> <flag name="stateUnspecified" value="0" /> <flag name="stateUnchanged" value="1" /> <flag name="stateHidden" value="2" /> <flag name="stateAlwaysHidden" value="3" /> <flag name="stateVisible" value="4" /> <flag name="stateAlwaysVisible" value="5" /> </attr> </declare-styleable> </resources>

      

    使用方法:attr name名+类型

    示范一:
    定义 <declare-styleable name = "color"> <attr name = "background" format = "reference|color" /> </declare-styleable> 使用 <ImageView android:background = "@drawable/图片ID|#00FF00" /> 示范二: 定义 <declare-styleable name="orient">   <attr name="orientation">   <enum name="horizontal" value="0" /> <enum name="vertical" value="1" /> </attr> </declare-styleable>

    使用
    <LinearLayout
      android:orientation = "horizontal" />

    示范三:
    定义
    <declare-styleable name="name">
      <attr name="windowSoftInputMode">
        <flag name="stateUnspecified" value="0" />
        <flag name="stateUnchanged" value="1" />
        <flag name="stateHidden" value="2" />
      </attr>
    </declare-styleable>
    使用
    <activity
      andriod:windowsSotfInputMode = "stateUpspecified | stateUnchanged"/>

      

  • 相关阅读:
    数据结构----字典及部分知识总结(2018/10/18)
    数据结构----链表的逆置及链表逆置和删除极小值
    Python自学知识点----Day03
    Python自学知识点----Day02
    Python自学知识点----Day01
    课堂笔记及知识点----树(2018/10/24(pm))
    课堂笔记及知识点----栈和队列(2018/10/24(am))
    数据结构----链表的删除和遍历(2018/10/24)
    数据结构----顺序表的增和遍历(2018/10/23)
    知识点回顾及委托(2018/10/22)
  • 原文地址:https://www.cnblogs.com/wabi87547568/p/5369596.html
Copyright © 2011-2022 走看看