Themes, styles and support Library android

5

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 RatingBar . 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?

    
asked by anonymous 07.01.2016 / 01:20

1 answer

3

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.

The 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 Theme.AppCompat (1) to res/values/styles.xml .
  • Set a theme with the same name inherited from the Material theme in res/values-v21/styles.xml .
  • Set this theme as the theme of your application in the manifest file.
  • No res/values/styles.xml do not use the android: prefix when referring to only existing attributes after API level 21 .
  • Use res/values-v21/styles.xml to set styles / themes that not are compatible with the pre- API level 21 versions, always use the android:

For more information, see documentation .

After AppCompat v21.1.1 you will have to inherit from Theme.AppCompat.Light.NoActionBar or Theme.AppCompat.Dark.NoActionBar and you will need to use Toolbar instead of ActionBar sub>

    
07.01.2016 / 12:34