首页 > 其他 > 详细

View 属性

时间:2019-12-26 01:42:16      阅读:92      评论:0      收藏:0      [点我收藏+]

关于 View 设置属性的方式:
Java
xml
style
defStyleAttr
defStyleRes
Theme


关于 defStyleRes 的使用,和在 xml 中声明 style=”@style/*“ 使用是一样的;
Theme 中定义,就是在当前应用使用的 theme 中,方式和 style 中定义的一样,其作用范围是全局的,只要有使用这个属性的地方,value 就是 theme 中定义的;
defStyleRes, defStyleAttr 的作用主要是用于自定义 View 中,想要使用该自定义 View 的地方都是这些属性


defStyleAttr 使用方法一般如下:
attr.xml

1
<attr name="ZTV_def_style" format="reference"/>

style.xml

大专栏  View 属性 class="highlight plain">
1
2
3
4
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<!-- Customize your theme here. -->
<item name="ZTV_def_style">@style/---</item>
</style>

然后定义你想要指定属性的 style, 再在自定义的 View 中使用 R.attr.ZTV_def_style


这几中方式的优先级:Java > xml > style > defStyleAttr > defStyleRes > Theme
原因可以根据使用的习惯想要,defStyleAttr > defStyleRes 在官方文档中有声明 defStyleRes used only if defStyleAttr is 0 or can not be found in the theme。

View 属性

原文:https://www.cnblogs.com/lijianming180/p/12099819.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!