首页 > Android 开发中,如何在支援 Material Design 的同时兼容到4.4以下的 Android 版本?

Android 开发中,如何在支援 Material Design 的同时兼容到4.4以下的 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 可以怎么做?

再次跪谢。


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


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

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

【热门文章】
【热门文章】