app:cornerRadius 不适用于 MaterialButton

app:cornerRadius doesn't work for MaterialButton

<com.google.android.material.button.MaterialButton
            android:id="@+id/button_tour"
            app:cornerRadius="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="30dp"
            android:layout_gravity="center_horizontal"
            android:text="Take a tour"/>

我在我的 android 项目中添加了一个 material 按钮,当我尝试使用 app:cornerRadius 设置圆角时,我发现它根本不起作用。

只需使用 material 主题。将样式中 AppTheme 的父级更改为某些 material 主题,例如Theme.MaterialComponents.Light.NoActionBar.因为 material 组件 需要 material 主题.

 <style name="AppTheme.Clinic" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>

创建一个新的可绘制资源,如下所示

<shape android:shape="rectangle">

     <corners android:radius="20dp" />

</shape>

并将其设置为 MaterialButton 的背景