简体   繁体   English

向后兼容 材料设计

[英]Backward compatibility Material design

How do I use material design .我如何使用材料设计。 here is my gradle .这是我的gradle

I want to use the material in my app.我想在我的应用程序中使用该材料。 I want to maintain the min target as 9.我想将最小目标保持为 9。

Please help请帮忙

 pply plugin: 'com.android.library'

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.1"

        defaultConfig {
            minSdkVersion 9
            targetSdkVersion 21
            versionCode 3
            versionName "1.0.1"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.2'
        compile 'com.android.support:cardview-v7:21.0.2'
    }

Whenever a new project is created in Android Studio, by default it comes with an attached AppCompat v7 library.每当在 Android Studio 中创建新项目时,默认情况下它都会附带一个 AppCompat v7 库。 Make sure that this support library is r21.确保这个支持库是 r21。 As this new release supports backward compatibility with material design.由于这个新版本支持与材料设计的向后兼容性。 To include it in you project add the line below in your :app build.gradle file:要将其包含在您的项目中,请在您的 :app build.gradle 文件中添加以下行:

compile 'com.android.support:appcompat-v7:21.0.3'

You can utilize the AppCompat library for displaying material theme by including code below in your regular styles.xml:您可以使用 AppCompat 库来显示材料主题,方法是在您的常规 style.xml 中包含以下代码:

styles.xml
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Main theme colors -->
        <!--   your app branding color for the app bar -->
        <item name="colorPrimary">#3F51B5</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="colorPrimaryDark">#303F9F</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="colorAccent">#FF4081</item>
    </style>
</resources>

or define the new layouts for v21(Android Lollipop), in res/layout-v21 folder of your project.或在项目的res/layout-v21文件夹中为 v21(Android Lollipop)定义新布局。 Your app will show these layout only when an Android 5.0 device is in use.只有在使用 Android 5.0 设备时,您的应用才会显示这些布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM