declare-styleable的详细用法

declare-styleable的详细用法简述declare-styleable的定义使用规则,做好笔记方便自己后期使用也方便他人使用。

大家好,又见面了,我是你们的朋友全栈君。

1.在resource中定义declare-styleable。

<declare-styleable name="SmileRating">
    <attr name="angryColor" format="color" />
    <attr name="normalColor" format="color" />
    <attr name="drawingColor" format="color" />
    <attr name="showLine" format="boolean" />
    <attr name="placeHolderSmileColor" format="color" />
    <attr name="placeHolderBackgroundColor" format="color" />
    <attr name="textSelectionColor" format="color" />
    <attr name="textNonSelectionColor" format="color" />
</declare-styleable>
2.使用:<com.XXX.XXXView>  
 android:id="@+id/ratingView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:angryColor="#fff"
    android:layout_centerVertical="true" />

3.在构造方法中获取属性值(注意getColor的key格式)

TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SmileRating);
Color1 = a.getColor(R.styleable.SmileRating_angryColor, defValue);
Color2 = a.getColor(R.styleable.SmileRating_normalColor, defValue);
Color3 = a.getColor(R.styleable.SmileRating_drawingColor, defValue);
a.recycle();

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/158544.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • sql2008r2绿色版免安装_少女都市模拟器中文版激活成功教程版免费

    sql2008r2绿色版免安装_少女都市模拟器中文版激活成功教程版免费中文版本64位免激活成功教程SQLyog-12.5.064位中文激活成功教程版 百度云盘https://pan.baidu.com/s/1yvQ7f0esY8idqc_Ci3Su2Ahttps://pan.baidu.com/s/1mhFLVpm 原文:https://blog.csdn.net/odyssey1816/article/details/78801342…

    2022年9月24日
    4
  • hashmap底层实现原理和源码分析(python底层源码)

    HashMap是Java开发中常用的集合,那么从我们创建一个空集合到,put添加、get获取元素经历了那些步骤呢?说明:以下源码基于JDK1.7,32位0.HashMap底层的数据结构是数组加链表的形式,存储结构如下图:1.创建一个新的HashMap集合的构造函数://初始默认数组的大小staticfinalintDEFAULT_INITIAL_CAPACITY=1&lt;&lt;…

    2022年4月16日
    48
  • TCN代码实现[通俗易懂]

    TCN代码实现#导入包importosimporttorchfromtorchimportnnfromtorch.autogradimportVariableimportpicklefromtorch.nn.utilsimportweight_normimportargparseimporttimeimportmathimporttorch.o…

    2022年4月7日
    137
  • chmod 755 filename「建议收藏」

    chmod 755 filename「建议收藏」chmod755filenamechmod755filenameFunctionAttentionchmod755filenameFunctionTochangethelimitofyourfilesAttentionwhenyouwanttochangethelimitofadirectory,youshouldbecarefultouse‘-R’after‘chmod’,becausethetotalsub-directori

    2022年7月16日
    16
  • python字符串与数字的转化_字符串转数字c语言

    python字符串与数字的转化_字符串转数字c语言数字转为字符串这个相对比较简单我们可以使用Python中的str函数直接转换例如将123转换为’123’print(str(123))或者使用格式化print(‘%s’%123)字符串转为数字这个相对比较复杂一点因为Python没有提供类似于str函数的int函数如果转换的是0-9的一个数,那么只采用字典就可实现defchar2num(s):…

    2022年10月12日
    2
  • voliate 关键字「建议收藏」

    voliate 关键字「建议收藏」voliatecpu术语定义术语英文单词术语描述内存屏障cachebarriers处理器的指令,用于实现对内存操作的顺序限制原子操作atomicopers不可中断的一个操作缓存行填充cachelinefill当处理器识别到内存的读操作是可缓存的,处理器读取整个缓存行到适合的缓存(L1,L2,L3)缓存命中cachehit当进行高速缓存行填充的内存位置不变时,处理器从缓存中读取,而非内存写命中writehitpp写

    2022年6月3日
    63

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号