Hello since I started working with Android development, I’ve always had a hard time understanding how Android’s Themes, Styles, and libs part of Android support works, I always have for example, to stylize a
EditText or a
For example, I was currently styling a
RatingBar where I had the following item on my theme:
<style name="CustomActionBarTheme" parent="Theme.AppCompat"> <item name="android:ratingBarStyle">@style/customRatingBar</item> <style name="customRatingBar" parent="android:Widget.RatingBar"> <item name="android:progressDrawable">@drawable/ratingbar_full_holo_dark</item> <item name="android:indeterminateDrawable">@drawable/ratingbar_full_holo_dark</item> </style>
In API 23 it worked quietly, however for it to work in smaller APIS I had to by the following code in style-v11
<style name="CustomActionBarTheme" parent="Theme.AppCompat"> <item name="android:ratingBarStyle">@style/customRatingBar</item> <item name="ratingBarStyle">@style/customRatingBar</item> </style>
What I want to understand is, what is the difference between
android : and without
android: in the item?
These attributes are only available from API level 21 . In order for them to be used in previous versions we will have to resort to those that are defined in the appCompat api .
In order for these styles / themes to be applied either to run on pre-devices or to run on devices at API level 21 you must set them twice, prefix
android: and another without the prefix.
android: prefix refers to the name of the package where style is defined and should be used for API level 21 in> (or higher, that to
compileSdkVersion refers to).
Not using the prefix is to refer to the styles / themes defined in the appCompat api .
The following procedure is as follows:
- Set a theme inherited from
- Set a theme with the same name inherited from the Material theme in
- Set this theme as the theme of your application in the manifest file.
res/values/styles.xmldo not use the
android:prefix when referring to only existing attributes after API level 21 .
res/values-v21/styles.xmlto set styles / themes that not are compatible with the pre- API level 21 versions, always use the
For more information, see documentation .
After AppCompat v21.1.1 you will have to inherit from
Theme.AppCompat.Dark.NoActionBar and you will need to use Toolbar instead of ActionBar sub>