材质设计组件按钮全局主题覆盖已损坏 [英] Material design components button global theme overriding broken

本文介绍了材质设计组件按钮全局主题覆盖已损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to simply apply styling to all buttons on a theme level like this

<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中

Why doesnt this work? It would in appcompat

//如果使用Theme.MaterialComponents.Light.NoActionBar.Bridge,则可以正常工作

// If I use Theme.MaterialComponents.Light.NoActionBar.Bridge, then it works

推荐答案

您应该在主题中设置materialButtonStyle而不是buttonStyle.

You should be setting materialButtonStyle instead of buttonStyle in your theme.

这篇关于材质设计组件按钮全局主题覆盖已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆