材料设计,AppCompat和向后兼容性 [英] Material Design, AppCompat, and Backwards Compatibility

查看:112
本文介绍了材料设计,AppCompat和向后兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更好地理解使用Material Design的原理(我是该领域的新手,并且已经阅读过文档和教程,但是该主题对我来说仍然有点模糊),我将很高兴获得一些帮助.到目前为止,我尝试过的是有2个文件夹(值和values-21),每个文件夹都有一个styles.xml文件-

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:

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>

问题开始于我尝试使用从AppCompatActivity继承的活动(据我所知,这是为了支持Lollipop之前在设备上向后兼容材料设计之类的东西?我正确吗?更多信息这里会很棒).如果这样做,该应用程序将无法在具有API 21或更高版本的设备上运行,因为"AppTheme"必须继承自AppCompat.

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.

我可以做的就是创建一个从AppCompat继承的基础主题,然后使两个文件中的样式都继承自该基础主题……但是,我不再从Material继承. ...这使我想到了一个问题-

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) -

材料设计只是给定的主题吗?如果是这样,我该如何解决我的问题?在这里使用AppCompatActivity到底能完成什么工作?还是材料设计本质上只是我应该遵循的一组规则和原则?如果是这样,为什么我们根本需要Theme.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? 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.

谢谢!

推荐答案

AppCompat的全部要点是,您只需要一个主题(在values-v21中不需要单独的主题),就可以得到相同的体验在所有设备上.

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已经在API 21+上扩展了android:Theme.Material-它只是为您处理所有版本检查.

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

这篇关于材料设计,AppCompat和向后兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆