I. References to style and attr
1. When the style of the reference platform is the parent of the style, "@android: style/Theme" = = "@android: Subject" = = "android:style/Theme" = = "Android: Theme";
2. When referencing the platform's style as a property, "@android: style/theme";
3. When referencing a custom style as the parent of another style, the "@style/subject" = = "style/Theme" = = "Theme";
4. "@style/Theme" When referencing a custom style as a reference to another property;
5. When referencing a platform property as a reference to a property, the "? android:attr/property" = = "? Android: Properties";
6. When referencing a custom attribute, "? attr/property" = = "?";
7. In the above six cases, can be at ' @ ' or '? ' After adding ' * ' to refer to the resources that are hidden (that is, the platform private);
8. If you reference a platform resource or attribute, you can put "Android:" After the slash "/" , that is, @android: style/Theme "= = @style/android: Theme", "? Android:attr/property "= ="? Attr/android: Attribute ";
Second, how to customize the properties
1:
<resources>
<attr name= "ANR" >
<enum name= "None" value= "0"/>
<enum name= "thumbnail" value= "1"/>
<enum name= "Drop" value= "2"/>
</attr>
</resources>
After defining the attribute in this way, the other <declare-styleable> blocks can be used directly, but not with any name or format description, e.g:
<declare-styleable name= "TextView" >
<attr name= "ANR" >
</declare-styleable>
The following is an error:
<declare-styleable name= "TextView" >
<attr name= "ANR" format= "string" >
</declare-styleable>
Because this is equivalent to redefining the "ANR", this is not allowed. Therefore, attributes that appear outside the,<declare-styleable> block take precedence over attributes that appear within the <declare-styleable> block, that is, if <declare-styleable> A property with the format description appears in the block, and an attribute with the same name (without the format description) outside the <declare-styleable> block is incorrect.
In addition, if format is specified for a property that first appears in <declare-styleable> , this property can be used directly in the other <declare-styleable> . However, no other format can be specified. This situation is similar to using attributes that first appear <declare-styleable> blocks .
Therefore, properties outside of the <declare-styleable> block are best to indicate the format description for use within the <declare-styleable> block.
e.g:
If
<resources>
<attr name= "ANR"/>
</resources>
And then
Or
<declare-styleable name= "TextView" >
<attr name= "ANR" >
<enum name= "None" value= "0"/>
<enum name= "thumbnail" value= "1"/>
<enum name= "Drop" value= "2"/>
</attr>
</declare-styleable>
These are all wrong!
2:
<declare-styleable name= "Theme" >
<attr name= "Colortext" format= "Color|reference"/>
<attr name= "Colorforeground" format= "Color"/>
<attr name= "colorforegroundinverse" format= "Color"/>
</declare-styleable>
The premise of defining attributes in this way is that there is no previous definition of Colortext, Colorforeground,colorforegroundinverse. The same as the first, in the future <declare-styleable> block can be used directly, but no other changes, e.g:
<declare-styleable name= "TextView" >
<attr name= "Colortext" >
</declare-styleable>
Or:
<declare-styleable name= "TextView" >
<attr name= "Colortext" >
<attr name= "Colorforeground" >
</declare-styleable>
But here's the error:
<declare-styleable name= "TextView" >
<!--no longer have format= "color|reference" description-
<attr name= "Colortext" format= "Color|reference" >
<attr name= "Colorforeground" >
</declare-styleable>
Third, how to use the platform's own properties
e.g:
<declare-styleable name= "Fragmentarguments" >
<!--cannot have format description--
<attr name= "Android:label"/>
</declare-styleable>
At this point, there will be a definition of the attribute inside R.styleable, named Fragmentarguments_android_label.
However, you cannot redefine the properties that the platform comes with, e.g:
<resources>
<attr name= "Android:label"/>
</resources>
But you can do this:
<resources>
<attr name= "label" format= "string"/>
</resources>
How to inherit a style
You can use the dot '. ' and "parent" to inherit the custom style, you can only use "parent" if you want to inherit the platform style.
Iv. How to inherit style
You can use the dot '. ' and "parent" to inherit the custom style, you can only use "parent" if you want to inherit the platform style.
e.g:
1.
<style name= "Hellotheme" parent= "@android: Style/theme.light" >
<item name= "Colorforeground" > #770000 </item>
<item name= "Colorbackground" > #000000 </item>
<item name= "Colortext" > #00ff00 </item>
<item name= "Android:windowbackground" > @drawable/windowoverlay </item>
<item name= "Android:windownotitle" >false</item>
</style>
2.
<style name= "hellotheme" parent= "Hellotheme.myhellotheme";
<item name= "Windowbackground" > @drawable/overlaybk </item>
<item name= "Colortext" > #00ff00 </item>
< /style>,
<style name= "Hellotheme.hello";
<!--<item name= "Android:background" >?ATTR/WINDOWBACKGROUND</ITEM>-->
<!--<item name= "Android:textcolor" >?attr/colorText</item>-->
<item name= "Android:background" >?windowbackground</item
<item name= "Android:textcolor" >?colorText</item>
</style>
3.
<style name= "Holo" >
<item name= "Textviewstyle" > @style/hellotheme.hello</item>
</style>
4.
<style name= "Holo.textviewstyle"/>
If you use Holo.textviewstyle for a textview, it does not play any role. Should be used directly:
<style name= "Textviewstyle" >
<item name= "Android:background" >?windowBackground</item>
<item name= "Android:textcolor" >?colorText</item>
</style>
Or
<style name= "Textviewstyle_1" parent= "Textviewstyle" >
Or
<style name= "Textviewstyle.textviewstyle_1" >
a Property Reference (reference) can be passed, of course, if windowbackground and colortext are used in the theme of the app or activity (theme), in the example above:
<item name= "Android:background" >?windowBackground</item>
<item name= "Android:textcolor" >?colorText</item>
equivalent to:
<item name= "Android:background" > @drawable/overlaybk</item>
<item name= "Android:textcolor" > #00ff00 </item>
because, Windowbackground and Colortext as a reference to two properties, have been set here:
<style name= "Hellotheme" parent= "Hellotheme.myhellotheme" >
<item name= "Windowbackground" > @drawable/overlaybk </item>
<item name= "Colortext" > #00ff00 </item>
</style>
When you customize a property, the inherited platform specified at the parent has an attribute that occasionally prompts for a resource that does not exist
e.g:
Parent= "@android: Style/textappearance.holo.light.inverse"
Error:error Retrieving parent for item:no Resource found that matches the given name ' @android: Style/textappearance.holo . Light.inverser '.
This notation is wrong, although there is a definition of the attribute within the data/res/styles.xml of the platform, but there is no textappearance_holo_light_inverse within the Android.r.style class of the platform, Because such properties are private properties of the platform, they are not exposed. So, you can't use Android. R.style.textappearance_holo_light_inverse.
to avoid errors, you can write: parent= "@*android:style/textappearance.holo.light.inverse", or remove ' @ ' and/or ' style/'.
Finally, if there is a dot '. ' In the name of the style, and "parent" is used, the style inherits only the '. ' In the ' name ' of the Style,style that the parent points to. will not work. If '. ' appears within the ' name ' of the style, and the ' parent ' is not used, then the dot in name is '. ' The previous name must exist in the definition. And if you use the parent,name inside dot '. ' Any previous name may not exist in the definition.
Five, "Android:" appeared before ' @ ' and '? ' The Difference
This is often the case when you define a style, such as:
This is often the case when you define a style, such as:
<style name= "Theme.iconmenu" parent= "Theme.holo" >
<!--Menu/item Attributes--
<item name= "Android:itemtextappearance" > @android:style/textappearance.widget.iconmenu.item</item>
<item name= "Android:itembackground" >?android:attr/selectableItemBackground</item>
<item name= "Android:itemicondisabledalpha" >?android:attr/disabledAlpha</item>
<item name= "Android:horizontaldivider" > @android:d rawable/divider_horizontal_dark</item>
<item name= "Android:verticaldivider" > @android:d rawable/divider_vertical_dark</item>
<item name= "Android:windowanimationstyle" > @android:style/animation.optionspanel</item>
<item name= "Android:moreicon" > @android:d rawable/ic_menu_more</item>
<item name= "Android:background" > @null </item>
</style>
among them, <item name= "Android:itemtextappearance" > @android: Style/textappearance.widget.iconmenu.item</item > indicates that "Android:itemtextappearance" is a style type that references another style of the platform ( TextAppearance.Widget.IconMenu.Item). and <item name= "Android:itemicondisabledalpha" >?android:attr/disabledAlpha</item> Indicates that the property value of "Android:itemicondisabledalpha" refers to Disabledalpha under the current topic .