Apply Material Design (android: Theme.Material) for Android versions smaller than API 21?

4

I was studying a little bit about the Android layout guidelines like:

So I tried to customize my theme , like this:

<resources>
  <!-- inherit from the material theme -->
  <style name="AppTheme" parent="android:Theme.Material">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>

But the attributes, android:colorPrimary , android:colorPrimaryDark and android:colorAccent , are only available for recent versions of Android (API 21+), which is not currently my target .

>

Then I took another path, customizing the components manually. So I tried to set StatusBar color, using the setStatusBarColor(int color) method, but this is also not available for versions prior to API 21.

Questions:

  • Is there a way to set a solid color for the StatusBar, for Android API 21- (Be it XML, or code)?
  • There is some AppCompat that provides compatibility of "Material" themes with version smaller than API 21?
  • Is there any other way to get this result, for Android API 21 -?
  • Important notes

    • My minTarget is API 14.
    asked by anonymous 08.04.2015 / 21:32

    1 answer

    1

    For smaller versions than api 21, you only create two styles 1- for 21, follow the example of how to implement in smaller versions.

    <resources>
    
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primary</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="colorAccent">@color/accent</item>
    </style>
    

        
    12.08.2015 / 21:23