关于 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。

最新文章

  1. JS.中文乱码,Jsp\Servlet端的解决办法
  2. SQL学习整理_1
  3. 【引】objective-c,6:Autorelease Pool
  4. Atitit. 类与对象的存储实现
  5. IOS绘图
  6. 进程通信之一 使用WM_COPYDATA C++及C#实现(转)
  7. javascript第一课练习
  8. Kaggle入门
  9. CodeForces 617E XOR and Favorite Number
  10. Android 根据字符串动态获取资源ID
  11. 1.由浅入深解析 SimpleDateFormat
  12. jmeter使用手册
  13. django使用ckeditor上传图片
  14. [HEOI2016/TJOI2016]树
  15. babel-loader和webpack UglifyJS一起使用时console的问题
  16. matlab 设定坐标比例
  17. 【wireshark】总体结构
  18. node的 node-sass@^4.11.0 出现:npm: no such file or directory, scandir &#39;.../node_modules/node-sass/vendor&#39;
  19. 更改npm全局模块和cache默认安装位置
  20. (转)用javamail发送带附件的邮件

热门文章

  1. PHP 5.3 新特性
  2. ILSVRC2012下载
  3. ThreadPoolExecutor自定义线程池
  4. 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)
  5. mysql创建某个数据库中的某张表 只读用户
  6. The website is API(1)
  7. day02-文件操作
  8. bwa index|amb|ann|bwt|pac|sa
  9. QuickSort(快速排序)原理及C++代码实现
  10. HotSpot Java对象创建,内存布局以及访问方式