Doubt with style files (styles.xml) on Android

1

On Android it is possible to make several style files, one for each version of the level of API (16, 19, 21 ...), for each type of screen (xxxdp) and so on. But I had a question: is there any inheritance between these files?

For example: I'm working on a project where the minimum level of API is 16 ( JellyBean ). For this, I have 3 style files: one for API 16 , one for API 19 and one for API 21 . However, within these files, I'm defining the same thing (well saying) 3 times:

API 21:     

    <style name="AppTheme.Base" parent="android:Theme.Material.Light.NoActionBar.TranslucentDecor">
        <item name="">@color/blue_500</item>
        <item name="">@color/blue_700</item>
        <item name="">@color/amber_a700</item>
        <!--<item name="">true</item>-->
        <item name="alertDialogProTheme">@style/Theme.AlertDialogPro.Material.Light</item>
    </style>

    <style name="DarkToolbar" parent="AppTheme.Base">
        <item name="">@color/abc_primary_text_material_dark</item>
        <item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
        <item name="">@color/abc_primary_text_material_dark</item>
    </style>
</resources>

API 19:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/blue_500</item>
        <item name="colorPrimaryDark">@color/blue_700</item>
        <item name="colorAccent">@color/amber_a700</item>
        <item name="">true</item>
        <!--<item name="">true</item>-->
        <item name="alertDialogProTheme">@style/Theme.AlertDialogPro.Material.Light</item>
    </style>

    <style name="DarkToolbar" parent="AppTheme.Base">
        <item name="">@color/abc_primary_text_material_dark</item>
        <item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
        <item name="">@color/abc_primary_text_material_dark</item>
    </style>
</resources>

API 16:

<resources>

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/blue_500</item>
        <item name="colorPrimaryDark">@color/blue_700</item>
        <item name="colorAccent">@color/amber_a700</item>
        <!--<item name="">true</item>-->
        <item name="alertDialogProTheme">@style/Theme.AlertDialogPro.Material.Light</item>
    </style>

    <style name="DarkToolbar" parent="AppTheme.Base">
        <item name="">@color/abc_primary_text_material_dark</item>
        <item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
        <item name="">/abc_primary_text_material_dark</item>
    </style>
</resources>

My question is: If I only set the colors used in colorPrimary , colorPrimaryDark and colorAccent , and set the DarkToolbar style only once, I need to reset them for each summer of API, in other words, re-assign the values for each version of Android that my app supports?

Edit: When I try to run the application using the XMLs above, I received an error saying that I should use the "AppCompat" theme instead of the "Material" theme, but the phone I'm testing is API 21 (Android 5.0) should support the Material theme. Any tips on what it might be?

    
asked by anonymous 03.03.2015 / 18:58

1 answer

1

I believe that if all your styles are derived from AppCompat you can use a default attribute to be used in all styles. Below is a very simple example.

strings.xml (API: 21)

<resources>
    <string name="text_info">Minha API é 21!!!</string>
</resources>

strings.xml (API: 19)

<resources>
    <string name="text_info">Minha API é 19+!!!</string>
</resources>

strings.xml (API: Default)

<resources>
    <string name="text_info">Minha API não é 19 e nem 21</string>
    <string name="text_info2">Esse texto vai ser mostrado em todas as APIS!</strings>
</resources>

Above, you can see that each XML has a string with different content. But in%% default, we have XML that does not appear in other text_info2 . When you show this text, the system will check if the settings for API 21 have this text, if it does not, it will show the default text. And ... back to the subject: yes, when you put a default value in your style setting, if there is no configuration for your current API , the system will use the value of% default%.

    
03.03.2015 / 23:36