Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between R.styleable, R.style and R.attr?

Tags:

What are the differences between R.styleable, R.style and R.attr? I found TextAppearance in all of these three classes.

like image 634
Zahid Hasan Avatar asked Jan 02 '13 21:01

Zahid Hasan


People also ask

What is r attr?

R. attr is used to define attributes for custom views.

What is Styleable?

Filters. Capable of being styled. adjective. (computing) Capable of being formatted with styles. adjective.


1 Answers

R.style has all styles android provided (including all Theme android provided). E.g., Theme.Translucent, Widget.AbsListView.

R.attr has all attrs android provided (that could be set to view or window). E.g., layout_width can be set to view, windowIsFloating can be set to window.

R.styleable has all attrs of a specific view or window that android provided AND can be defined in a style. E.g., FrameLayout_Layout_layout_gravity: layout_gravity can be styled for FrameLayout, Window_windowIsFloating: Flag indicating whether this is a floating window.

To answer your question, TextAppearance is a attribute (R.attr) AND it is declared styleable, 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>

Just in case you don't understand what the "?" means, check: Question mark (?) in XML attributes for Android And in case you are puzzled by what is declare-styleable, check: Difference between declare-styleable and style

like image 143
Helin Wang Avatar answered Sep 26 '22 18:09

Helin Wang