在 KitKat 上使用 Android L Material Design
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24633162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Android L Material Design on KitKat
提问by Luca
Reading the Compatibility section of Android L Developer Preview (http://developer.android.com/preview/material/compatibility.html) I've seen that i can create an APP using L-sdk and also be able to run it on older sdk (like KitKat).
阅读 Android L 开发者预览版 ( http://developer.android.com/preview/material/compatibility.html)的兼容性部分,我看到我可以使用 L-sdk 创建一个应用程序,也可以在较旧的 sdk(如 KitKat)。
I've created a new project using Android L sdk and configured "build.gradle" as said in this post: Android Studio : Failure [INSTALL_FAILED_OLDER_SDK].
我已经使用 Android L sdk 创建了一个新项目并配置了“build.gradle”,如本文所述:Android Studio : Failure [INSTALL_FAILED_OLDER_SDK]。
I've tried both the configurations:
我已经尝试了两种配置:
the one proposed in question that gives me this error:
pkg: /data/local/tmp/com.example.{my user name}.materialapp Failure [INSTALL_FAILED_OLDER_SDK]
and the one proposed in answer that gives me error on
<style name="AppTheme" parent="android:Theme.Material.Light"></style>
有问题的那个给了我这个错误:
pkg: /data/local/tmp/com.example.{my user name}.materialapp Failure [INSTALL_FAILED_OLDER_SDK]
而在回答中提出的那个让我错误
<style name="AppTheme" parent="android:Theme.Material.Light"></style>
I've searched on others question on StackOverflow but I can't find no solutions.
我在 StackOverflow 上搜索了其他问题,但找不到任何解决方案。
SOLUTION: Android L previewmaterial style can be used only on devices that run Android L. The "compatibility" is only a preview and it's not enabled.
解决方案:Android L预览材质样式只能在运行 Android L 的设备上使用。“兼容性”只是一个预览,并未启用。
采纳答案by Booger
You have to create 2 different styles.xml files with the same name that you will put in different folders.
您必须使用相同的名称创建 2 个不同的 styles.xml 文件,并将它们放在不同的文件夹中。
The first, will go here:
第一个,会去这里:
res/styles.xml
and will look NOT have a reference to the Material theme (use the Holo theme):
并且看起来没有对 Material 主题的引用(使用 Holo 主题):
so would have something like this:
所以会有这样的事情:
<style name="AppTheme" parent="android:Theme.Holo.Light"></style>
The second will go here:
第二个将在这里:
res/values-v21/styles.xml
and WILL contain the reference to the new Material theme, and would have:
并且将包含对新 Material 主题的引用,并且将具有:
<style name="AppTheme" parent="android:Theme.Material.Light"></style>
The Android framework will automatically use the correct one depending on which API the device supports (so on API 21 devices it will use Material, and on all other devices, it will use whatever else you define).
Android 框架将根据设备支持的 API 自动使用正确的 API(因此在 API 21 设备上它将使用 Material,而在所有其他设备上,它将使用您定义的任何其他内容)。
回答by Booger
This has changed since the original answer, as Google released better support for Material design in the AppCompat libraries (which support mostly all versions of Android).
自从最初的答案以来,这已经发生了变化,因为 Google 在 AppCompat 库(主要支持所有版本的 Android)中发布了对 Material design 的更好支持。
At this point, you should be using these libraries for all development, then you will be able to support Material design related features in all your apps.
此时,您应该将这些库用于所有开发,然后您将能够在所有应用程序中支持 Material Design 相关功能。
Here is how to set it up: https://developer.android.com/topic/libraries/support-library/setup.html
以下是设置方法:https: //developer.android.com/topic/libraries/support-library/setup.html