Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android style - difference between @style, android:, @android:style, etc

In android developer examples, blogs, etc, I have seen multiple prefixes for the values of style attributes. Can someone please describe when to use what? For example, what is the difference between these 3 cases?

parent="@android:style/TextAppearance"
parent="TextAppearance.AppCompat"
parent="@style/TextAppearance.AppCompat"

What is the difference between these 2 cases?

<item name="colorControlNormal">@color/white</item>
<item name="android:colorControlNormal">@color/white</item>
like image 665
clocksmith Avatar asked Mar 29 '16 20:03

clocksmith


2 Answers

Without any prefix references the style named on the same file.

@Style references your style.xml project file.

@android:style references defined Android API style.

More about Style Resource and Style and Themes.

About colorControlNormal vs android:colorControlNormal is the same explanation. If you use controlColorNormal you are defining the color applied to framework controls in their normal state in you app. If you use android:colorControlNormal you are overwriting the the color default applied to framework controls by the system.

like image 137
Gustavo Morales Avatar answered Sep 20 '22 12:09

Gustavo Morales


You can think of @ as signaling that a named resource is coming up.

@type/name identifies a resource of type type (string, color, layout, style etc) with name name defined in the app is coming up.

@+id/name identifies an id resource called name that will be created if it doesn't already exist (whereas @id simply refers to an id that already exists).

@android:type/name means that the named resource is part of the Android platform is coming up (it's not defined in the app -- it's provided by the device).

For style parents, the @style is optional. You can refer to styles directly by name. It's redundant because you can't derive a style from anything other than another style anyway.

like image 43
Doug Stevenson Avatar answered Sep 19 '22 12:09

Doug Stevenson