简体   繁体   English

材料设计,AppCompat和向后兼容性

[英]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. 我正在尝试更好地理解使用Material Design的原理(我是该领域的新手,并且已经阅读过文档和教程,但是该主题对我来说仍然有些模糊),我将为此感到高兴一些帮助。 What I've tried so far is having 2 folders (values and values-21) with a styles.xml file per each of them - 到目前为止,我尝试过的是有2个文件夹(值和values-21),每个文件夹都有一个styles.xml文件-

values/styles.xml: values / styles.xml:

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

values-v21/styles.xml: 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). 问题开始于我尝试使用从AppCompatActivity继承的活动(据我所知,这是为了在Lollipop之前支持诸如材料设计之类的设备上向后兼容的设备上需要做的事情?我正确吗?大)。 If I do that, the app won't run on devices that have API 21 or above, since "AppTheme" has to inherit from AppCompat. 如果这样做,该应用程序将无法在具有API 21或更高版本的设备上运行,因为“ AppTheme”必须继承自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) - 为了解决这个问题,我要做的是创建一个继承自AppCompat的基础主题,然后使两个文件中的样式都继承自该基础主题...但是后来我不再继承Material了。这使我想到了一个问题-

Is Material Design just a given theme? 材料设计只是给定的主题吗? And if so, how do I solve my problem? 如果是这样,我该如何解决我的问题? And what does using AppCompatActivity exactly accomplish here? 在这里使用AppCompatActivity到底能完成什么工作? 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? 如果是这样,为什么我们根本需要Theme.Material。*? I'll be glad for any extra info anyone can give me on the subject. 任何人都可以给我提供有关该主题的任何其他信息,我会很高兴。

Thanks! 谢谢!

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. AppCompat的全部要点是,您只需要一个主题(在values-v21不需要单独的主题),并且在所有设备上的体验都是相同的。

Theme.AppCompat already extends android:Theme.Material on API 21+ - it is just handling all of the version checking for you. Theme.AppCompat已经在API 21+上扩展了android:Theme.Material它只是为您处理所有版本检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM