推薦開發者使用 Material Design 組件

爲了保證您的應用與用戶設備中安裝的其餘應用在視覺和行爲上保持一致,咱們 推薦 您遵循 Material Design 規範,由於用戶從一個應用中學習的操做模式能夠無縫銜接地在另外一個應用中使用。html

Android 用戶但願您的應用在視覺和行爲上與系統保持一致。您在設計視覺和導航模式時應該遵循 Material Design 規範…android

—— d.android.com/designgit

您可使用 Material Design Components (MDC) 組件庫來 實現 這一目的。本文將列出使用 MDC 的優點,從而說明咱們推薦使用它的緣由。github

組件

MDC 提供了系統標準組件的 Material 版本,例如 ButtonsToolbarsCheckBox 等等,使用這些組件能輕鬆實現 Material 風格。若是您使用了 MaterialComponents 主題,當您 inflate 一個 layout (經過 MDC 的 View Inflater) 時,被實例化是 Material 組件而不是標準組件,所以您不須要對佈局進行重大的更新就能輕鬆實現 Material 風格。segmentfault

<!-- Copyright 2019 Google LLC.
   SPDX-License-Identifier: Apache-2.0 -->

<!--  標準組件 Button 將會被替換爲 MaterialButton -->
<Button ... />

<!-- 您甚至可使用 MaterialButton 特定的屬性 -->
<Button ...
  app:icon="@drawable/foo"/>

<!--若是您想用具備向後兼容能力的 AppCompatButton 而不是 MaterialButton,您能夠這樣作 -->
<androidx.appcompat.widget.AppCompatButton ... />

全部 Material 組件都繼承自對應的 AppCompat 組件,所以它們享有相同的向後兼容能力和新版本的 bug 修復。app

Material 組件在對應的系統標準組件和 AppCompat 組件的基礎上拓展出更多樣式和功能,例如 MaterialButton 擁有如下多種樣式:less

<!-- Copyright 2019 Google LLC.  
   SPDX-License-Identifier: Apache-2.0 -->

<!-- Contained button -->
<Button ... 
  style="?attr/materialButtonStyle"/>

<!-- Text button -->
<Button ... 
  style="?attr/borderlessButtonStyle"/>

<!-- Outlined button -->
<Button ... 
  style="?attr/materialButtonOutlinedStyle"/>

我最喜歡的功能之一是使用 MaterialTextView 替換 TextView,它 新增的功能 能夠很方便地在 TextAppearance 中設置行高。工具

除了拓展示有組件的功能外,MDC 還提供了一系列全新的組件。您可能知道 Bottom NavigationBottom SheetFloating Action Button,但未必據說過 ChipsDate PickerTime Picker佈局

MDC 提供的所有組件列單,請查閱 —— 組件學習

Material 主題

Material 主題 能夠更系統地 自定義 Material Design 樣式來體現您的產品品牌。Material 主題包括 顏色字體樣式形狀 屬性。對其進行自定義將自動應用到您用於構建應用的組件上。

您能夠將 Material 主題理解爲建立設計系統的設計系統 🤯。您只需配置好顏色、字體樣式和形狀,便可獲得一套基於您品牌的完整設計系統。

Nick Rout 在如下文章中分別深刻地介紹了這三個子系統:

深色主題

MDC 組件遵循 Material 的 深色主題背景規範 實現了深色主題。在深色主題下,許多組件都將調整它們的顏色,而且在陰影不可見的狀況下添加了 elevation 疊加層以表現高度變化。

Chris Banes 在下面這篇文章中深刻介紹了 MDC 的深色主題:

Material 動效 🆕

Material Design 還針對轉場動畫制定了規範。如今,MDC 不只提供了 規範,還將這些模式實現爲 Transition 以便您在應用中使用。

Hunter Stich 在下面這篇文章中介紹了 Material Motion 庫:

使用 Compose

Jetpack Compose 是 Android 系統的下一代 UI 工具包,目前 已正式發佈。它會提供 Material 風格的組件和主題。儘早使用 MDC 將爲將來遷移至 Jetpack Compose 作好準備 — 它們使用了相同的概念、設計名詞和組件。您甚至可使用相似 MDC-Android Compose 主題適配器 的庫來簡化遷移過程,該庫將 XML 實現的 MDC 主題轉換爲 Compose 的 MaterialTheme

推薦使用 Material

但願您已經清楚咱們推薦使用 Material Design Components 構建 Android UI 的緣由。咱們 近期更新 了在 Android Studio 中經過 File > New Project 菜單新建的模版,這些模版爲您預設置了 Material 主題並使用了 MDC,所以您能夠更容易的開始使用 MDC。若是您尚未遷移到 MDC,請查看咱們的 遷移指南

相關文章
相關標籤/搜索