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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ICP证书_dwcc2018怎么用

    ICP证书_dwcc2018怎么用输入44 21 2 4 84 0100 99 98 972 210000 100005 30 0 0 0 1696RichmanImpossible代码#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e5 + 10;int a[N];int main(){ int T; cin>>T; while(T -..

    2022年8月11日
    8
  • Spring batch教程 之 配置Step「建议收藏」

    Spring batch教程 之 配置Step「建议收藏」正如在BatchDomainLanguage中叙述的,Step是一个独立封装域对象,包含了所有定义和控制实际处理信息批任务的序列。这是一个比较抽象的描述,因为任意一个Step的内容都是开发者自己编写的Job。一个Step的简单或复杂取决于开发者的意愿。一个简单的Step也许是从本地文件读取数据存入数据库,写很少或基本无需写代码。一个复杂的Step也许有复杂的业务规则(取决于所实现的方式),并作

    2022年5月28日
    38
  • 手把手教你用idea搭建ssm项目并实现简单demo(超详细)

    手把手教你用idea搭建ssm项目并实现简单demo(超详细)闲暇之余,想搭建一个ssm项目玩玩,结果发现,不百度根本打不出来,搭建出来也有一堆问题,所以在此一步一步记录一下。使用idea搭建ssm项目,首先就是将整个框架整起来如果已经在项目中了,点击左上角file->new->project(刚打开idea是新建->project)[image1]左侧栏目选择maven并勾选createfromarchetype,然后在下面找到org.apache.maven.archetype:maven-archetype-weba

    2022年6月16日
    44
  • ubuntu 设置samba 精要说明

    ubuntu 设置samba 精要说明

    2021年4月30日
    168
  • Mysql on duplicate key update用法及优缺点

    Mysql on duplicate key update用法及优缺点

    2022年2月19日
    38
  • vc 调用dll_调用API

    vc 调用dll_调用APIGoogle公司已经将GoogleCOMAPI开放,这样我们就可以通过开放的API来对GoogleEarth进行操作了,比如控制当前视图的高度、中心经纬度,保存当前图片等等。下面是GoogleCOMAPI的网址:http://earth.google.com/comapi/那么,VC程序员如何使用这些API来控制GoogleEarth呢?下面我们编写一个简单的程序来说明对G

    2022年8月12日
    9

发表回复

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

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