Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android "?colorPrimary" vs "?attr/colorPrimary"?

I can't find any information about the differences between:

android:textColor="?attr/colorPrimary"

vs

android:textColor="?colorPrimary"

I have read that "?attr" means attribute value specified in the current theme, but without "attr" it gives the same result (=color defined in my theme). It behaves similar with other attributes?

For example:

Does android:background="?attr/selectableItemBackground" equals android:background="?selectableItemBackground" ?

Here it's told that it differs.

Thanks very much.

like image 623
Derek K Avatar asked Jun 06 '17 13:06

Derek K


People also ask

What does ATTR mean in Android?

attr/ references to attributes. Attributes are values specified in an app's theme. The attributes in your example are all values specified in the themes provided by the support library. Android also has its very own attributes which can be used with ? android:attr/ .

What is colorPrimary in Android Studio?

colorPrimary and colorSecondary represent the colors of your brand. colorPrimaryVariant and colorSecondaryVariant are lighter or darker shades of your brand colors. colorSurface is used for “sheets” of material (like cards and bottom sheets) android:colorBackground is the window background color of your app.

What is Coloronprimary?

colorPrimary. The color displayed most frequently across your app's screens and components. This color should pass accessibilty guidelines for text / iconography when drawn on top of the surface or background color.

What is colorControlNormal in Android?

colorControlNormal controls the 'normal' state of components such as an unselected EditText, and unselected Checkboxes and RadioButtons.


1 Answers

Ok, I have finally found in the docs:

Because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type (which would be ?android:attr/textColorSecondary)—you can exclude the attr type.

So, I deducted it's like this: the AppCompat library attributes are treated as custom attributes and as a result we point them by a question mark without "android" keyword. And "attr" is type of resource which is optional for both platform and custom attributes (from docs). Android documentation

like image 51
Derek K Avatar answered Sep 19 '22 03:09

Derek K