android declare-styleable 和style,Android 关于declare-styleable属性的写法….

android declare-styleable 和style,Android 关于declare-styleable属性的写法….我想问自定义View的时候,以下这段代码,为何要写两次一样的名称呢?我看了一些资料,说写在declare-styleable系统会自动生成数组…..我不太明白这实际应用是什么?如果说自动帮你生成了数组,方便使用,那写在外面的三个又有什么作用?能从实际应用中讲一讲吗?<?xmlversion=”1.0″encoding=”utf-8″?><resources><at…

我想问自定义View的时候,以下这段代码,为何要写两次一样的名称呢?

我看了一些资料,说写在declare-styleable系统会自动生成数组…..

我不太明白这实际应用是什么?

如果说自动帮你生成了数组,方便使用,那写在外面的三个又有什么作用?

能从实际应用中讲一讲吗?

<?xml version=”1.0″ encoding=”utf-8″?>

<resources>

<attr name=”titleText” format=”string” />

<attr name=”titleTextColor” format=”color” />

<attr name=”titleTextSize” format=”dimension” />

<declare-styleable name=”CustomTitleView”>

<attr name=”titleText” />

<attr name=”titleTextColor” />

<attr name=”titleTextSize” />

</declare-styleable>

</resources>

=========================================

那可以简写把?

<declare-styleable name=”CustomTitleView”>

<attr name=”titleText” format=”string” />

<attr name=”titleTextColor” format=”color” />

<attr name=”titleTextSize” format=”dimension” />

</declare-styleable>

自定义style

声明和引用的关系,外面的三个是声明了三个属性的名称及可赋值类型,CustomTitleView则是引用了三个外面声明的属性,表明了CustomTitleView下有三个属性。

应用时,比如在style.xml下引用到了CustomTitleView这个style,就可以对三个属性赋值,生成特定的style

73bccf0c0b4af35beddca4274520fb45.png

今天的文章android declare-styleable 和style,Android 关于declare-styleable属性的写法….分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/31871.html

(0)
编程小号编程小号

相关推荐

发表回复

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