使用材质组件库,您可以通过应用主题自定义文本和按钮使用的textAppearance:
只需使用 snackbarButtonStyle 和 snackbarTextViewStyle 属性在应用中全局定义:
<style name="AppTheme" parent="Theme.MaterialComponents.*">
<!-- Style to use for action button within a Snackbar in this theme. -->
<item name="snackbarButtonStyle">@style/Custom.TextButton.Snackbar</item>
<!-- Style to use for message text within a Snackbar in this theme. -->
<item name="snackbarTextViewStyle">@style/Custom.Snackbar.TextView</item>
....
</style>
然后,对于 按钮,您可以定义应用 android:textAppearance 属性的自定义样式
<style name="Custom.TextButton.Snackbar" parent="@style/Widget.MaterialComponents.Button.TextButton.Snackbar">
<item name="android:textAppearance">@style/snackbar_button_textappearance</item>
</style>
这只是一个例子:
<style name="snackbar_button_textappearance" parent="@style/TextAppearance.MaterialComponents.Button">
<item name="android:textStyle">italic</item>
</style>
对于 text,您可以执行类似的操作:
<style name="Custom.Snackbar.TextView" parent="@style/Widget.MaterialComponents.Snackbar.TextView">
<item name="android:textAppearance">......</item>
</style>
请注意:
-
snackbarButtonStyle 属性需要 1.1.0 版本
-
snackbarTextViewStyle 属性需要 1.2.0 版本。