在 KitKat 上使用 Android L Material Design [英] Using Android L Material Design on KitKat

查看:22
本文介绍了在 KitKat 上使用 Android L Material Design的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 Android L 开发者预览版的兼容性部分(http://developer.android.com/preview/material/compatibility.html) 我已经看到我可以使用 L-sdk 创建一个应用程序,也可以在旧的 sdk(如 KitKat)上运行它.

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 sdk 创建了一个新项目并配置了build.gradle",如本文所述:Android Studio:失败 [INSTALL_FAILED_OLDER_SDK].

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].

这两种配置我都试过了:

I've tried both the configurations:

  • 有问题的建议给了我这个错误:

  • the one proposed in question that gives me this error:

pkg:/data/local/tmp/com.example.{我的用户名}.materialapp失败 [INSTALL_FAILED_OLDER_SDK]

以及在回答中提出的那个给我错误的

and the one proposed in answer that gives me error on

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

我在 StackOverflow 上搜索了其他问题,但找不到任何解决方案.

I've searched on others question on StackOverflow but I can't find no solutions.

解决方案:Android L 预览 材质样式只能在运行 Android L 的设备上使用.兼容性"只是一个预览,并没有启用.

SOLUTION: Android L preview material style can be used only on devices that run Android L. The "compatibility" is only a preview and it's not enabled.

推荐答案

您必须创建 2 个具有相同名称的不同 style.xml 文件,并将它们放在不同的文件夹中.

You have to create 2 different styles.xml files with the same name that you will put in different folders.

第一个,会在这里:

res/styles.xml

并且看起来没有对 Material 主题的引用(使用 Holo 主题):

and will look NOT have a reference to the Material theme (use the Holo theme):

所以会有这样的事情:

<style name="AppTheme" parent="android:Theme.Holo.Light"></style>

第二个会在这里:

res/values-v21/styles.xml

并且将包含对新 Material 主题的引用,并且:

and WILL contain the reference to the new Material theme, and would have:

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

Android 框架将根据设备支持的 API 自动使用正确的 API(因此,在 API 21 设备上,它将使用 Material,而在所有其他设备上,它将使用您定义的任何其他内容).

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

这篇关于在 KitKat 上使用 Android L Material Design的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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