Reputation: 3391
Could somebody please tell me what the difference is between
?android:attr/colorPrimary
and
?attr/colorPrimary
Whichever i use, result is the same. Altough first option causes android.view.InflateException
on some devices.
Upvotes: 2
Views: 1068
Reputation: 7982
The builder knows that the color comes from attr
so it's redundant. The documentation states:
... you do not need to explicitly state the type ... you can exclude the attr type.
See: App resources overview: Referencing style attributes
As for android:
- the prefix in android:colorPrimary
refers to an attribute of the material theme (API 21 and later). Without the prefix, ?colorPrimary
will be taken from the support library.
Upvotes: 2
Reputation: 759
Both almost works the same often. when you use ?attr/colorPrimary
, its works totally fine as compiler already knows that 'android' has to be appended.
And regarding you saying that ?android:attr/colorPrimary
gives you exception then in that case, try using the second option only ..
For Example in your styles.xml : The following may/may not work everytime
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">@color/primary_material_dark</item>
<item name="android:colorPrimaryDark">@color/primary_dark_material_dark</item>
</style>
</resources>
But this majorly works :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary_material_dark</item>
<item name="colorPrimaryDark">@color/primary_dark_material_dark</item>
</style>
Upvotes: 2