Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Design, AppCompat, and Backwards Compatibility

I'm trying to understand the principles of using Material Design a bit better (I'm new to this area and have been reading documentations and tutorials, but the subject is still a bit vague to me), and I'll be glad for some help. What I've tried so far is having 2 folders (values and values-21) with a styles.xml file per each of them -

values/styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>

values-v21/styles.xml:

<style name="AppTheme" parent="android:Theme.Material.NoActionBar"></style>

The problem begins where I try to use activities that inherit from AppCompatActivity (To my understanding, that's what I need to do in order to support backwards compatibility on devices before Lollipop for things such as Material Design? Am I correct? More info here would be great). If I do that, the app won't run on devices that have API 21 or above, since "AppTheme" has to inherit from AppCompat.

What I can do to solve that, is to create a base theme that inherits from AppCompat , and then make the style in both files to inherit from that base theme... But then I'm not inheriting from Material anymore.... which brings me to the question(s) -

Is Material Design just a given theme? And if so, how do I solve my problem? And what does using AppCompatActivity exactly accomplish here? Or is Material Design essentially just a set of rules and principles I'm supposed to follow? And if so, why do we need Theme.Material.* at all? I'll be glad for any extra info anyone can give me on the subject.

Thanks!

like image 256
Cookienator Avatar asked Mar 23 '26 05:03

Cookienator


1 Answers

The whole point of AppCompat is that you only need one theme (you don't need a separate one in values-v21) and it will be the same experience on all devices.

Theme.AppCompat already extends android:Theme.Material on API 21+ - it is just handling all of the version checking for you.

like image 114
ianhanniballake Avatar answered Mar 25 '26 18:03

ianhanniballake