declare-styleable是给自定义控件添加自定义属性用的 attr中 在attrs.xml中设置declare-styleable,name是PersonAttr <? > <resources> <declare-styleable name="PersonAttr"> <attr name="name" format="reference attr name="adult" format="boolean" /> <attr name="textSize" format="dimension" /> </declare-styleable > </resources> format就是格式,里面的就是这个属性对应的格式,下面列出来大致的格式有: reference:参考某一资源ID,以此类推 属性定义: <declare-styleable name = "名称"> <attr name = "background" format = "reference" /> </declare-styleable> 属性使用: <ImageView
在attrs.xml中,您可以直接在“资源”部分内或在“declare-styleable”中声明自定义属性: 所以现在我们将“attrib1”定义为不风格,“attrib2”为风格。
我看了一些资料,说写在declare-styleable系统会自动生成数组….. 我不太明白这实际应用是什么? 如果说自动帮你生成了数组,方便使用,那写在外面的三个又有什么作用? /> <attr name=”titleTextColor” format=”color” /> <attr name=”titleTextSize” format=”dimension” /> <declare-styleable CustomTitleView”> <attr name=”titleText” /> <attr name=”titleTextColor” /> <attr name=”titleTextSize” /> </declare-styleable <declare-styleable name=”CustomTitleView”> <attr name=”titleText” format=”string” /> <attr name=”titleTextColor ” format=”color” /> <attr name=”titleTextSize” format=”dimension” /> </declare-styleable> 自定义style 声明和引用的关系
declare-styleable是给自定义控件添加自定义属性用的 1.首先,先写attrs.xml <?xml version="1.0" encoding="utf-8"? > <resources> <declare-styleable name="TestAttr"> <attr name="name" format="reference" / name="oldman" value="60" /> </attr> <attr name="textSize" format="dimension" /> </declare-styleable
> <resources> <declare-styleable name="ExTextView"> <attr name="enableOnPad" format="boolean " /> <attr name="supportDeviceType" format="reference"/> </declare-styleable> <declare-styleable > <resources> <declare-styleable name="ExTextView"> <attr name="enableOnPad" format="boolean " /> <attr name="supportDeviceType" format="reference"/> </declare-styleable> <declare-styleable "/> </declare-styleable> </resources> 每次引用attr后,建议清理一下工程,确保R文件重新生成.
> <resources> <declare-styleable name=”ToolBar”> <attr name=”buttonNum” format=”integer 该文件是定义属性名和格式的地方,需要用<declare-styleable name=”ToolBar”></declare-styleable>包围所有属性。 1.定义: 1 2 3 <declare-styleable name="My"> <attr name="label" format="reference" > </declare-styleable </declare-styleable> 2.使用: 1 <Button zkx:myWidth="100dip"/> 五、float:浮点型 1.定义: 1 2 3 <declare-styleable " /> </declare-styleable> 2.使用: 1 <rotate zkx:pivotX="200%"/> 八、fraction:百分数 1.定义: 1 2 3 <declare-styleable
format 值类型 reference 资源ID color 颜色值 dimension 尺寸值 float 浮点值 string 字符串 fraction 百分数 <declare-styleable stateUnspecifed" value="0" /> <flag name="stateWindowvisible" value="1" /> </attr> </declare-styleable
1.定义: 1 2 3 <declare-styleable name=”My”> <attr name=”label” format=”reference” > </declare-styleable > 2.使用: 1 <Buttonzkx:label=”@string/label” > 二、Color:颜色 1.定义: 1 2 3 <declare-styleable name=”My”> < > </declare-styleable> 2.使用: 1 <Button zkx:isVisible=”false”/> 四、dimension:尺寸值 1.定义: 1 2 3 <declare-styleable ” /> </declare-styleable> 2.使用: 1 <alpha zkx:fromAlpha=”0.3″/> 六、integer:整型 1.定义: 1 2 3 <declare-styleable =”string” /> </declare-styleable> 2.使用: 1 <rotate zkx:pivotX=”200%”/> 八、fraction:百分数 1.定义: 1 2 3 <declare-styleable
最近在模仿今日头条,发现它的很多属性都是通过自定义控件并设定相关的配置属性进行配置,于是便查询了解了下declare-styleable,下面我把自己的使用感受和如何使用进行说明下。 declare-styleable:declare-styleable是给自定义控件添加自定义属性用的。 之后在里面配置declare-styleable ,name为PersonAttr <?xml version="1.0" encoding="utf-8"? name = “名称”> <attr name = “textColor” format = “color” /> </declare-styleable> 3. boolean:布尔值 <declare-styleable /> </declare-styleable> 5. float:浮点值。
定义: <declare-styleable name = "名称"> <attr name = "background" format = "reference " /> </declare-styleable> 使用: <ImageView android:layout_width = "42dip" name = "名称"> <attr name = "focusable" format = "boolean" /> </declare-styleable> name = "名称"> <attr name = "layout_width" format = "dimension" /> </declare-styleable name = "名称"> <attr name = "background" format = "reference|color" /> </declare-styleable>
(1)属性定义: <declare-styleable name = "名称"> <attr name = "background" format = "reference" /> </declare-styleable (1)属性定义: <declare-styleable name = "名称"> <attr name = "textColor" format = "color" /> </declare-styleable (1)属性定义: <declare-styleable name = "名称"> <attr name = "focusable" format = "boolean" /> </declare-styleable (1)属性定义: <declare-styleable name = "名称"> <attr name = "layout_width" format = "dimension" /> </declare-styleable (1)属性定义: <declare-styleable name = "MapView"> <attr name = "apiKey" format = "string" /> </declare-styleable
(1)属性定义: <declare-styleable name = "名称"> <attr name = "background" format = "reference" /> </declare-styleable (1)属性定义: <declare-styleable name = "名称"> <attr name = "textColor" format = "color" /> </declare-styleable (1)属性定义: <declare-styleable name = "名称"> <attr name = "focusable" format = "boolean" /> </declare-styleable (1)属性定义: <declare-styleable name = "名称"> <attr name = "layout_width" format = "dimension" /> </declare-styleable (1)属性定义: <declare-styleable name = "MapView"> <attr name = "apiKey" format = "string" /> </declare-styleable
--在该集合下,设置不同的自定义属性--> <declare-styleable name="CircleView"> <! > </resources> 对于自定义属性类型 & 格式如下: <-- 1. reference:使用某一资源ID --> <declare-styleable name="名称"> <attr name="background" format="reference" /> </declare-styleable> // 使用格式 <ImageView android:layout_width name="名称"> <attr name="layout_width" format="dimension" /> </declare-styleable> // 格式使用: <Button android:apiKey="0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g" /> <-- 8. fraction:百分数 --> <declare-styleable
--在该集合下,设置不同的自定义属性--> <declare-styleable name="CircleView"> <! > </resources> 对于自定义属性类型 & 格式如下: <-- 1. reference:使用某一资源ID --> <declare-styleable name="名称"> <attr name="background" format="reference" /> </declare-styleable> // 使用格式 <ImageView android:layout_width name="名称"> <attr name="layout_width" format="dimension" /> </declare-styleable> // 格式使用: <Button android:apiKey="0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g" /> <-- 8. fraction:百分数 --> <declare-styleable
问题描述 今天在使用 “cordova build android” 的时候,发现报下面的错误 ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings ERROR: In <declare-styleable> FontFamilyFont, unable ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex FAILURE: Build
attr> <attr name="lineColor" format="color"></attr> //自定义控件的主题样式 //MySportView样式名称 <declare-styleable /attr> <attr name="outCircleColor"></attr> <attr name="inCircleColor"></attr> </declare-styleable > <declare-styleable name="MyQQHealthView"> <attr name="titleColor"></attr> <attr name="lineColor"></attr> </declare-styleable> </resources>
先来看看第一种情况,这个好解决 : 只需将力哥styleable里的<atrr name="icon" /> ,并在资源的最外层定义<atrr name="icon" format="integer" /> <declare-styleable <enum name="normal" value="0"/> <enum name="mini" value="1"/> </attr> </declare-styleable > <declare-styleable name="B"> <attr name="colorPressed" format="color"/> <attr name= <enum name="normal" value="0"/> <enum name="mini" value="1"/> </attr> </declare-styleable
当然是在values文件夹下新建attrs.xml <declare-styleable name="title"> <attr name="name" format="string "/> </declare-styleable> 生成TypedArray是用的declare-styleable的name,生成对应的string是在两个name中加下划线 用法 <com
> <resources> <declare-styleable name="BoldTextView"> <attr name="textIsBlod" format="boolean " /> </declare-styleable> </resources> 2、创建一个类继承自TextView,很简单,内容都是前面讲过的 public class BoldTextView 1、自定义属性 <declare-styleable name="ImgBtn"> <attr name="imgbtn_title" format="string" /> <attr name="imgbtn_icon" format="reference" /> </declare-styleable> 2、组合控件布局 <LinearLayout xmlns:android
FAILED Total time: 29.304 secs Error: cmd: Command failed with exit code 1 Error output: ERROR: In <declare-styleable > FontFamilyFont, unable to find attribute android:font ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontStyle ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontWeight ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute