Android 材质设计组件按钮全局主题覆盖已断开

Android 材质设计组件按钮全局主题覆盖已断开,android,material-design,android-button,material-components,material-components-android,Android,Material Design,Android Button,Material Components,Material Components Android,我想简单地将样式应用于主题级别上的所有按钮,如下所示 <style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> ... <item name="buttonStyle">@style/DefaultButton</item> </style> <style name="DefaultButton" parent="Wid

我想简单地将样式应用于主题级别上的所有按钮,如下所示

<style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
     ...    
    <item name="buttonStyle">@style/DefaultButton</item>
</style>

<style name="DefaultButton" parent="Widget.MaterialComponents.Button">
    <item name="android:textColor">@color/whatever</item>
</style>

<Button
    android:id="@+id/addChannelButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_margin="16dp"
    android:text="Add room" />

...    
@样式/默认按钮
@颜色/随便什么
为什么这不起作用?它将在appcompat中运行


//如果我使用
Theme.MaterialComponents.Light.NoActionBar.Bridge
,那么它可以工作你应该在你的主题中设置
materialButtonStyle
,而不是
buttonStyle

你能试试v1.0.0-alpha06吗?自v1.0.0以来,已经取得了一些进展,这可能解决了您所看到的问题

1.1.0-02
  • 形状主题化:浮动操作按钮、材质按钮、芯片、材质CardView、底板和文本输入布局已更新,以使用新的材质形状系统
1.1.0-6
  • 在MaterialButton中实现可成形界面

来源:

使用
materialButtonStyle
并使用
MaterialButton
而不是
按钮
使用定义属性的主题

  <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light">
    ....

    <item name="materialButtonStyle">@style/MyButtonTheme</item>
  </style>

目前它需要android library的material components版本1.1.0

有效,但它现在忽略了我的背景设置(自定义形状可绘制),我是否可以通过materialButtonStyle覆盖所有内容?(使用桥主题和按钮样式时,背景会起作用)
  <style name="MyButtonTheme" parent="Widget.MaterialComponents.Button">
    <item name="materialThemeOverlay">@style/ButtonStyleTextColor</item>
  </style>

  <style name="ButtonStyleTextColor">
    <!-- For filled buttons, your theme's colorPrimary provides the default background color of the component, and -->
    <!--the text color is colorOnPrimary -->
    <item name="colorOnPrimary">@color/my_color</item>

  </style>