现在的位置: 首页 > web前端 > 正文

declare styleable代码怎么写

2020年07月16日 web前端 ⁄ 共 892字 ⁄ 字号 评论关闭

  declare-styleable:declare-styleable是给自定义控件添加自定义属性用的。


  declarestyleable先写attrs.xml


  在res-vlaues文件夹下创建资源文件attrs.xml或则自定义一个资源文件xx.xml,都可以。


  之后在里面配置declare-styleable,name为PersonAttr


  declarestyleable代码


  [html]viewplaincopy


  在CODE上查看代码片派生到我的代码片


  <?xmlversion="1.0"encoding="utf-8"?>


  <resources>


  <declare-styleablename="PersonAttr">


  <attrname="name"format="reference"/>


  <attrname="sex"format="reference"/>


  <attrname="age"format="integer"/>


  <attrname="weight">


  <flagname="fat"value="2"/>


  <flagname="mid"value="1"/>


  <flagname="thin"value="0"/>


  </attr>


  <attrname="adult"format="boolean"/>


  <attrname="textSize"format="dimension"/>


  </declare-styleable>


  </resources>


  我这里设置了姓名name,性别sex,年龄age,以及特征属性weight(fat,mid,thin内部的3个属性及对应的属性值),还有是否成年adult,和TextView的字体大小textView。


  可能这里有人会问,format是什么,里面的单词代表的又是什么意思。


  format就是格式,里面的就是这个属性对应的格式,下面列出来大致的格式有:


  总之,declarestyleable给大家简单的介绍了一些,希望大家多看看。


  

抱歉!评论已关闭.