再不迁移到Material Design Components 就out啦 (5)

@color对于包含的按钮文本颜色,我们还应该使用新的“ on”颜色属性

<!-- Copyright 2020 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <Button - android:textColor="@android:color/white" + android:textColor="?attr/colorOnPrimary" ... /> 字体板式

新的 TextAppearance 样式/属性

MDC字体板式直接从Material Design类型系统中提取。表达的意思就是紧贴 Material Design 风格

引入了一组新的TextAppearance.MaterialComponents.*样式和相应的textAppearance*主题属性,它们替代了现有的AppCompat /框架样式。

再不迁移到Material Design Components 就out啦


再不迁移到Material Design Components 就out啦

MDC小部件使用这些属性来设置文本样式。要知道哪些窗口小部件使用哪种类型板式,需要检查源代码中的默认窗口小部件样式。

请参阅下面的完整类型样式和属性映射表: 13 种类型

AppCompat文字样式 MDC-Android文字样式 MDC-Android文字属性
TextAppearance.AppCompat.Display4   TextAppearance.MaterialComponents.Headline1   textAppearanceHeadline1  
TextAppearance.AppCompat.Display3   TextAppearance.MaterialComponents.Headline2   textAppearanceHeadline2  
TextAppearance.AppCompat.Display2   TextAppearance.MaterialComponents.Headline3   textAppearanceHeadline3  
TextAppearance.AppCompat.Display1   TextAppearance.MaterialComponents.Headline4   textAppearanceHeadline4  
TextAppearance.AppCompat.Headline   TextAppearance.MaterialComponents.Headline5   textAppearanceHeadline5  
TextAppearance.AppCompat.Title TextAppearance.AppCompat.Large   TextAppearance.MaterialComponents.Headline6   textAppearanceHeadline6  
TextAppearance.AppCompat.Subhead TextAppearance.AppCompat.Menu   TextAppearance.MaterialComponents.Subtitle1   textAppearanceSubtitle1  
TextAppearance.AppCompat.Small   TextAppearance.MaterialComponents.Subtitle2   textAppearanceSubtitle2  
TextAppearance.AppCompat.Body1   TextAppearance.MaterialComponents.Body1   textAppearanceBody1  
TextAppearance.AppCompat.Body2   TextAppearance.MaterialComponents.Body2   textAppearanceBody2  
TextAppearance.AppCompat.Button   TextAppearance.MaterialComponents.Button   textAppearanceButton  
TextAppearance.AppCompat.Caption   TextAppearance.MaterialComponents.Caption   textAppearanceCaption  
不适用   TextAppearance.MaterialComponents.Overline   textAppearanceOverline  
例子 <com.google.android.material.card.MaterialCardView ...> ... <TextView android:id=”@+id/headerText” - android:textAppearance="@style/TextAppearance.AppCompat.Title" + android:textAppearance="?attr/textAppearanceHeadline6" ... /> <TextView android:id=”@+id/subheadText” android:textColor="?android:attr/textColorSecondary" - android:textAppearance="@style/TextAppearance.AppCompat.Body2" + android:textAppearance="?attr/textAppearanceBody2" ... /> <TextView android:id=”@+id/supportingText” android:textColor="?android:attr/textColorSecondary" - android:textAppearance="@style/TextAppearance.AppCompat.Body2" + android:textAppearance="?attr/textAppearanceBody2" ... /> </com.google.android.material.card.MaterialCardView> 自定义

我们还可以选择在应用程序主题中覆盖类型比例,以使用自定义字体系列,XML或通过Android Studio 下载字体:

<!-- Copyright 2020 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <style parent="Theme.MaterialComponents.*"> ... + <item>@style/TextAppearance.App.Headline6</item> + <item>@style/TextAppearance.App.Body2</item> </style> +<style + parent="TextAppearance.MaterialComponents.Headline6"> + <item>@font/roboto_mono_medium</item> +</style> +<style + parent="TextAppearance.MaterialComponents.Body2"> + <item>@font/roboto_mono_regular</item> +</style>

上面我们只是重写了 13 种类型中的一种。如果你想要改变字体的话,建议也把剩余的 12 修改了,以保持APP中字体的一致性。

Shape

ShapeAppearance styles/attributes

Shape( Material Design shape system) 是用来处理 MDC 控件的边角的一种方式,分成了小,中,大

这些合适的样式属性来自 ShapeAppearance.* styles。包括:cornerFamily (两种值:rounded cut) 。用 cornerSize 来表示尺寸

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zypxxp.html