android - R.styleable、R.style 和 R.attr 之间有什么区别?

标签 android

R.styleable、R.style 和 R.attr 有什么区别? 我在所有这三个类中都找到了 TextAppearance。

最佳答案

R.style 拥有android提供的所有样式(包括android提供的所有Theme)。例如,Theme.TranslucentWidget.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/

相关文章:

Android Debounce/TakeLast RxJava 在 OnCompleted() 之后从未收到最后一项

android - 无法从设备访问服务器,在模拟器中工作

java - 是否可以创建自定义 ImageView ?

java - FirebaseUI -Android 电子邮件链接登录不起作用

android - 如何获取从 onReceive() 触发的 Intent 的名称或类型

android - 无法创建媒体播放器(使用 url)

android - iOS 和 Android 中的 Firebase OTP 身份验证消息不同

我的应用程序中的 Android 模拟器 Internet 连接

java - 添加 TextChangedListener 时应用崩溃

java - 如何在 whatsapp 和 facebook 分享 libgdx 游戏得分的截图?