Repeating style in v19/v21

前端 未结 3 872
情话喂你
情话喂你 2021-01-01 20:58

I have this in my styles.xml:



    
    

Now you can apply AppTheme in your manifest file and the system selects the styles available for each system version.

  1. Is there a way to just call it in the main styles.xml and have it apply everywhere so I don't have to write it multiple times?

Yes, there is a way in which you can maintain only one styles.xml file.

First of all, start using AppCompat themes. They provide backward compatibility and will work for older android versions as well.

Now define all of your styles in styles.xml(default) file and if your Android Studio is showing you some warning/error for some attribute which is supported in higher level apis:

You can suppress that warning using: tools:targetApi="SupportedAndroidVersionName"

Now Android will ignore that particular attribute if it's not supported and your whole style will work perfectly for both lower and higher api levels.

Read more about Styles and Themes here.

Hope it helps :)

提交回复
热议问题