material-design - Android 开发中,如何在支援 Material Design 的同时兼容到4.4以下的 Android 版本?
迷茫
迷茫 2017-04-17 13:16:25
[Android讨论组]

新入门 Android 开发,求各位大大带路。。。

按照官方的描述,API 19 及以下是无法使用 Material Design 的,但是有向下兼容并使用 Holo 主题代替的方法的:

The material theme is only available in the Android L Developer Preview. To configure your app to use the material theme on devices running the Android L Developer Preview and an older theme on devices running earlier versions of Android:

Define a theme that inherits from an older theme (like Holo) in res/values/styles.xml. Define a theme with the same name that inherits from the material theme in res/values-v21/styles.xml. Set this theme as your app's theme in the manifest file.

然后我试图在res/values 文件夹下添加相应的文件来向下支援,然后发现如果我定义了 Action Bar 颜色的话,应用就会漂漂亮亮地闪退(5.1的测试机器)……

不定义颜色当然可以,但是造成的后果就是比较难看。

现在的问题就是:

  1. 如果使用原生 Material Design 支援的话,颜色应该如何进行设定才能保证在 API 19 以下以及 API 21 以上都能被诠释?
  2. API 19 以下如果希望支援 Material Design 可以怎么做?

再次跪谢。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(2)
大家讲道理

Material Design可以向下兼容的。在项目依赖里添加appcompat-v7这个库的21+版本,然后用Theme.AppCompat中的主题就可以。

这样做在4.x上只是看起来是Material Design,但是触摸反馈、动画等等与4.x无异。

巴扎黑

用一些开源UI库实现吧~ https://github.com/lightSky/MaterialDesignCenter

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号