Material Design, AppCompat, and Backwards Compatibility

浪子不回头ぞ 提交于 2019-11-26 09:14:00

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/39088064/material-design-appcompat-and-backwards-compatibility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!