AndroidAndroid开发Android开发经验谈

Material Design Compoents 1.1.0

2020-09-14  本文已影响0人  sydMobile

Material Design Compoents 1.1.0

增加了 Material Theming,新的组件、黑暗主题支持、等等

新的功能:

MDC的背景说明

Material Components for Android(MDC)是从以前的 Design Support Library 库演变而来,是与 AndroidX 来搭配的。考虑到版本兼容和过渡,一开始的 1.0.0 版本与 design 库 28.0.0 是等价的。命名发生了改变从 com.android.support.designcom.google.android.material 。不过后续更新 design 库就不再更新了,也就是说 design 库就永远的停留在了 1.0.0 这个版本了。

1.0.0 开始 Material Design 的规范不断发展。出现了新的规范、准则和新的组件,来更好的代表品牌同时保持了 Material 的核心原则。MDC 的目的是为开发者提供一个库,该库通过代码形式来实现这些组件和准则。随着指南不断的变化更新,MDC 将进行调整并更新来满足新的规范。

1.1.0 有什么新功能

MDC从 1.0.0 开始发生了大量的改变!如果你还在使用测试版或者1.0.0 请尽快迁移到 1.1.0 版本或者更新版本。

Material Theming

Material Theming 可以让你更好的自定义 Material Design 来体现我们的品牌、颜色、字体和形状的选择。

MDC 1.1.0 在您的 Android 应用中启用 Material Theming 。所有组件都支持通过主题、样式、新属性和自定义类(比如:MaterialShapeDrawable) 来调整其颜色、字体和形状。

// 这个地方要继承 Theme.MaterialComponents.*
<style name="Theme.MyApp" parent="Theme.MaterialComponents.*">    <!-- Color attributes -->
    <item name="colorPrimary">@color/green_500</item>
    <item name="colorPrimaryVariant">@color/green_700</item>
    <item name="colorOnPrimary">@color/black</item>
    <item name="colorSecondary">@color/orange_500</item>
    <item name="colorSecondaryVariant">@color/orange_300</item>
    <item name="colorOnSecondary">@color/black</item>
    <item name="colorError">@color/red_700</item>
    <item name="colorOnError">@color/white</item>
    <item name="colorSurface">@color/white</item>
    <item name="colorOnSurface">@color/black</item>
    <item name="android:colorBackground">@color/white</item>
    <item name="colorOnBackground">@color/black</item>    <!-- Type attributes -->
    <item name="textAppearanceHeadline1">
        @style/TextAppearance.MyApp.Headline1
    </item>
    <item name="textAppearanceHeadline2">
        @style/TextAppearance.MyApp.Headline2
    </item>
    <item name="textAppearanceHeadline3">
        @style/TextAppearance.MyApp.Headline3
    </item>
    <item name="textAppearanceHeadline4">
        @style/TextAppearance.MyApp.Headline4
    </item>
    <item name="textAppearanceHeadline5">
        @style/TextAppearance.MyApp.Headline5
    </item>
    <item name="textAppearanceHeadline6">
        @style/TextAppearance.MyApp.Headline6
    </item>
    <item name="textAppearanceSubtitle1">
        @style/TextAppearance.MyApp.Subtitle1
    </item>
    <item name="textAppearanceSubtitle2">
        @style/TextAppearance.MyApp.Subtitle2
    </item>
    <item name="textAppearanceBody1">
        @style/TextAppearance.MyApp.Body1
    </item>
    <item name="textAppearanceBody2">
        @style/TextAppearance.MyApp.Body2
    </item>
    <item name="textAppearanceCaption">
        @style/TextAppearance.MyApp.Caption
    </item>
    <item name="textAppearanceButton">
        @style/TextAppearance.MyApp.Button
    </item>
    <item name="textAppearanceOverline">
        @style/TextAppearance.MyApp.Overline
    </item>    <!-- Shape attributes -->
    <item name="shapeAppearanceSmallComponent">
        @style/ShapeAppearance.MyApp.SmallComponent
    </item>
    <item name="shapeAppearanceMediumComponent">
        @style/ShapeAppearance.MyApp.MediumComponent
    </item>
    <item name="shapeAppearanceLargeComponent">
        @style/ShapeAppearance.MyApp.LargeComponent
    </item>
    
</style>

新组件

Material Components 库中有很多新的组件添加到了 MDC 1.1.0 中。并且已经存在的组件也是通过最新的设计有了新的 style 如果您使用的是Design库或者 MDC 1.0.0 那么组件将自动采用这些新样式。例如,文字有新的默认的 appearance

MDC 1.1.0 中提供的一些新组件和更新组件包括:

黑色主题支持

在 Android 10 中引入了系统范围的深色主题支持。连同 Material Design 指南。MDC 可以立即使用 Material Dark 主题。它以现有的 AppCompat DayNight功能为基础,因此不用从头开始实现它:

Android 10 手势支持

手势导航是在 Android10 中引入的。某些 MDC 组件常常处于主手势的区域(比如,BottomNavigationView 以及从底部向上滑动的原始手势)。相关组件已经更新,以考虑这些手势区域以及设备方向。适当的 padding/margin 值会自动被申请,用 WindowInsets API(在 Android 10 或者更高版本)。

Accessibility improvements

许多可 accessibility 改进已经加入到 MDC 组件中。这主要包含更好的 "话语提示" 在有用的内容描述、功能和各部分的排序。例如,TextInputLayout现在按正确的顺序读取其提示,输入以及帮助程序或错误文本。

MDC的下一步计划

我们已经收到了您关于 MDC 版本的反馈。我们致力于更新并且整合您的重要贡献。

原文地址:https://medium.com/google-design/material-design-components-for-android-1-1-0-are-now-available-45e1d576037c

上一篇 下一篇

猜你喜欢

热点阅读