【问题标题】:Material Design Typography and Snackbars材料设计排版和小吃店
【发布时间】:2019-07-13 11:22:08
【问题描述】:

根据https://material.io/develop/android/theming/typography/,我一直在通过修改 textAppearanceX 属性来自定义我的应用程序的样式。有谁知道要自定义哪个属性来设置应用程序的 Snackbars 样式或记录在哪里?

谢谢。

【问题讨论】:

    标签: android material-design android-theme android-snackbar material-components-android


    【解决方案1】:

    使用材质组件库,您可以通过应用主题自定义文本和按钮使用的textAppearance

    只需使用 snackbarButtonStylesnackbarTextViewStyle 属性在应用中全局定义:

    <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 版本。

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2018-06-15
      • 1970-01-01
      • 2022-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      • 2022-09-28
      相关资源
      最近更新 更多