【问题标题】:MaterialButton style shapeAppearance not workingMaterialButton 样式 shapeAppearance 不起作用
【发布时间】:2021-05-16 01:13:49
【问题描述】:

我正在努力为项目中的按钮设置正确的样式。我不知道为什么shapeAppearance 不起作用。即使我只使用cornerSize,它也不起作用。

我有一个按钮的基本样式:

<style name="SnButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">
    <item name="shapeAppearance">@style/MyShapeAppearance</item>
    <item name="backgroundTint">@null</item>
</style>

这是我的按钮形状外观:

<style name="MyShapeAppearance" parent="ShapeAppearance.MaterialComponents.SmallComponent">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">2dp</item>
</style>

这是我的基本主题:Theme.MaterialComponents.Light.NoActionBar.Bridge

我应该怎么做才能强制shapeAppearance 在我的情况下工作?或者至少cornerSize

【问题讨论】:

    标签: material-design android-button material-components-android


    【解决方案1】:

    我知道为什么样式不起作用了!

    问题在于我设置按钮颜色的方式。我用过android:background,但必须用backgroundTint

    【讨论】:

    • 使用android:background MaterialButton 不使用自己的MaterialShapeDrawable 作为背景。这意味着形状外观、笔划和圆角等特征将被忽略。
    猜你喜欢
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 2023-03-07
    • 2019-10-09
    • 2019-02-23
    • 2014-12-22
    • 2014-06-05
    相关资源
    最近更新 更多