Material Design

官网

简介

为Android 设计。Android用户期望您应用外观和行为与平台一致。您不仅应遵Material Design指南设计视觉和导航模式,还应遵质量指南以保兼容性、性能和安全性等。以下链接提供设计优质Android应用所需一切资源。

资料

样式

官方
使用
<resources xmlns:tools="http://schemas.android.com/tools">

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <!--ShapeAppearance-->
        <item name="shapeAppearanceSmallComponent">@style/ShapeAppearance.MyApp.SmallComponent
        </item>
        <item name="shapeAppearanceMediumComponent">@style/ShapeAppearance.MyApp.MediumComponent
        </item>
        <item name="shapeAppearanceLargeComponent">@style/ShapeAppearance.MyApp.LargeComponent
        </item>
        <!--AlertDialog-->
        <item name="materialAlertDialogTheme">@style/ThemeOverlay.MyApp.Dialog</item>
    </style>

    <style name="ShapeAppearance.MyApp.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">@dimen/dp_4</item>
    </style>

    <style name="ShapeAppearance.MyApp.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">@dimen/dp_8</item>
    </style>

    <style name="ShapeAppearance.MyApp.LargeComponent" parent="ShapeAppearance.MaterialComponents.LargeComponent">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">@dimen/dp_4</item>
    </style>

    <style name="ThemeOverlay.MyApp.Dialog" parent="@style/ThemeOverlay.MaterialComponents.Dialog">
        <item name="android:dialogCornerRadius" tools:targetApi="p">@dimen/dp_4</item>
        <item name="android:paddingBottom">@dimen/dp_2</item>
    </style>
</resources>

使用

  • 依赖
    implementation 'com.google.android.material:material:1.1.0-alpha06'
    
  • 样式
    <resources>
    
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
    
    </resources>
    
    Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
    

问题

material-components-android

Demo