Using Android L Material Design on KitKat

橙三吉。 提交于 2019-12-03 18:59:14

问题


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

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

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

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.


回答1:


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

The first, will go here:

res/styles.xml

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

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:

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




回答2:


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

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.

Here is how to set it up: https://developer.android.com/topic/libraries/support-library/setup.html



来源:https://stackoverflow.com/questions/24633162/using-android-l-material-design-on-kitkat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!