R.styleable、R.style 和 R.attr 有什么区别? 我在所有这三个类中都找到了 TextAppearance。
最佳答案
R.style
拥有android提供的所有样式(包括android提供的所有Theme)。例如,Theme.Translucent
、Widget.AbsListView
。
R.attr
具有 android 提供的所有属性(可以设置为 View 或窗口)。例如,layout_width
可以设置为view,windowIsFloating
可以设置为window。
R.styleable
具有 android 提供的特定 View 或窗口的所有属性,并且可以在样式中定义。例如,FrameLayout_Layout_layout_gravity
:layout_gravity 可以为 FrameLayout 设置样式,Window_windowIsFloating
:指示这是否为 float 窗口的标志。
为了回答您的问题,TextAppearance 是一个属性 (R.attr) 并且它被声明为可设置样式,attrs.xml:
<attr name="textAppearance" format="reference" />
<declare-styleable name="TextViewAppearance">
<!-- Base text color, typeface, size, and style. -->
<attr name="textAppearance" />
</declare-styleable>
TextAppearance is also a Theme/Style (Theme is just a style), styles.xml:
<style name="TextAppearance">
<item name="android:textColor">?textColorPrimary</item>
<item name="android:textColorHighlight">?textColorHighlight</item>
<item name="android:textColorHint">?textColorHint</item>
<item name="android:textColorLink">?textColorLink</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
</style>
以防万一你不明白什么是“?”意思是,检查:Question mark (?) in XML attributes for Android 如果您对什么是 declare-styleable 感到困惑,请查看:Difference between declare-styleable and style
关于android - R.styleable、R.style 和 R.attr 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14129269/