• 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"/>

      

  • 相关阅读:
    ssm复习资料
    嵌入式开发实践的第二种柱状图代码
    嵌入式开发实践的简单登录代码
    嵌入式开发实践的柱状图代码
    学习ps的坑
    js的执行上下文
    js的渲染
    vue 使用Ueditor富文本的配置
    使用iview Upload进行多文件上传,编辑页初始已上传的图片失败的问题
    beforeEach钩子,next('/login') 跳转问题,无线循环导致Maximum call stack size exceeded问题
  • 原文地址:https://www.cnblogs.com/wabi87547568/p/5369596.html
Copyright © 2020-2023  润新知