• View 属性


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

  • 相关阅读:
    AlterDialog 经常使用的样式
    C++编程-&gt;pair(对组)
    arcgis server10.2.2公布地图基础服务的详细步骤
    solr实战-(一)
    iOS开发-自己定义重用机制给ScrollerView加入子视图
    Day2下午解题报告
    Day2二分图笔记
    考前冲刺班成绩
    Day2平衡树笔记
    Day2上午解题报告
  • 原文地址:https://www.cnblogs.com/lijianming180/p/12099819.html
Copyright © 2020-2023  润新知