
我是android开发的新手,我正在尝试创建我的自定义视图.我遇到了很多问题.我已经解决了其中一些问题,但最难理解的是属性.
我们来看一下带有属性的示例xml文件
<declare-styleable name="VIEwPagerIndicator"> <!-- Style of the circle indicator. --> <attr name="vpiCirclePageIndicatorStyle" format="reference"/> <!-- Style of the icon indicator's vIEws. --> <attr name="vpiIconPageIndicatorStyle" format="reference"/> <!-- Style of the line indicator. --> <attr name="vpilinePageIndicatorStyle" format="reference"/> <!-- Style of the Title indicator. --> <attr name="vpiTitlePageIndicatorStyle" format="reference"/> <!-- Style of the tab indicator's tabs. --> <attr name="vpiTabPageIndicatorStyle" format="reference"/> <!-- Style of the underline indicator. --> <attr name="vpiUnderlinePageIndicatorStyle" format="reference"/> </declare-styleable> <attr name="centered" format="boolean" /> <attr name="selectedcolor" format="color" /> <attr name="strokeWIDth" format="dimension" /> <attr name="unselectedcolor" format="color" /> <declare-styleable name="CirclePageIndicator"> <attr name="centered" /> <attr name="fillcolor" format="color" /> <attr name="pagecolor" format="color" /> <attr name="androID:orIEntation"/> <attr name="radius" format="dimension" /> <attr name="snap" format="boolean" /> <attr name="strokecolor" format="color" /> <attr name="strokeWIDth" /> <attr name="androID:background"/> </declare-styleable><declare-styleable name="linePageIndicator"> <attr name="centered" /> <attr name="unselectedcolor" /> <attr name="selectedcolor" /> <attr name="linewidth" format="dimension" /> <attr name="strokeWIDth" /> <attr name="gapWIDth" format="dimension" /> <attr name="androID:background"/></declare-styleable>>参考格式是什么意思,我还不明白这种格式是什么意思,我发现它可以用于drawables我也看到它可以用于主题.请举例说明它有用的地方以及这种格式类型的主要目的是什么.在前面的示例中,它用于样式,但我不明白如何在我将使用自定义视图的xml文件中使用它.
06001
>每个declare-styleable name =“自定义视图名称”行,我可以理解,用于单独的自定义视图,我们可以在示例中看到这一点.但是< declare-styleable name =“VIEwPagerIndicator”>的目的是什么,我没有在这个lib中找到任何具有这样名称的视图,这个样式包含我的第一个问题(引用属性).
>如果声明了declare-stylable属性,则意味着它在多个视图中,而不是在每个视图中重复代码,而是将公共属性放在外面.我对吗 ?
请帮助,我花了一天时间试图找到任何教程或文档.官方文件很差.我想很多新手都会对解释这个话题表示感谢.
请帮助理解这一点,最重要的问题是关于引用(第一次qustion)< attr name =“vpiCirclePageIndicatorStyle”format =“reference”/>这是什么,如何使用它,它被声明的地方?
另外我发现了另一个lib中使用的另一个例子
<declare-styleable name="themes"> <attr name="SlIDerStyle" format="reference"/> <attr name="PagerIndicatorStyle" format="reference"/></declare-styleable>我根本无法理解这一点.请帮忙,你是我最后的希望.
解决方法:
AFAIK,reference允许您引用该属性中的其他drawable和样式.
<declare-styleable name="theme"> <attr name="indicatorStyle" format="reference"/></declare-styleable>这允许我声明一个我以后可以获得的自定义样式
<style name="Apptheme.Platform.NoActionbar" parent="theme.AppCompat.NoActionbar"> <item name="indicatorStyle">@style/VIEwPagerIndicator</item></style>现在我可以在XML中使用它了
如果我尝试在未声明它的主题中使用此属性,我将收到错误.这就是VIEwPagerIndicator样式的用途,用于在app主题中声明自定义属性.我没有得到你的第三个问题,但这应该涵盖前两个问题.
总结以上是内存溢出为你收集整理的Android属性,声明样式,引用全部内容,希望文章能够帮你解决Android属性,声明样式,引用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)