Can't figure out how to style an Android app for pre-Lollipop devices using Theme.AppCompat

My brain is about to explode Android themes and... Someone help me please! I am trying to create a themefor my application to provide as similar search for pre- and post-Lollipop devices as possible . So, I inherited my theme from Theme.AppCompat.NoActionBar

and my actions from AppCompatActivity

ans configured colorPrimary

, colorPrimaryDark

and colorAccent

. Everything went well. The problems started when I was trying to style the background and text color. I installed android:textColorPrimary

and android:textColorSecondary

and got what I wanted on Lollipop device, but not on KitKat, so to add tags textColorPrimary

and textColorSecondary

to the subject and then Android Studio said that he can not create an application, because these attributes can not be found. The same thing happened when I tried to addcolorBackground

... I tried this, but couldn't find anything useful about what attributes are provided for what topic and what I should be using in my situation.

+3


source to share


2 answers


You need to create two folder values ​​for lollipop values-v21 and simple values for pre-lollipop

See this style for pre-leopted devices just paste it in values ​​/styles.xml

styles.xml



<resources>

    <style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

    </style>


    <style name="MyMaterialTheme.TransparentActivity">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:windowBackground">@color/windowBackground</item>
    </style>
</resources>

      

see android blog official documentation

+2


source


If you want to style your app for different apis, you need to make the folder name-v (sdk version) values ​​like values-v21 for lollipop, values-v19 for kitkat, ... but in this case, I think you need to create only values-v21.



inside this folder, create an xml file style.xml and api based to use the appropriate attributes.

+1


source







All Articles