属性 app:cornerRadius 不适用于 MaterialButton

Attribute app:cornerRadius doen't work for the MaterialButton

屏幕内部布局我正在尝试使用新的 Material 圆角组件 Material 按钮 Material 按钮

<android.support.design.button.MaterialButton
        android:text="@string/login"
        android:id="@+id/btnEntrance"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="104dp"
        style="@style/Widget.MaterialComponents.Button.UnelevatedButton" 
        android:layout_height="40dp"
        app:cornerRadius="8dp"/>

但是在预览屏幕上圆角是不可见的——这个属性不会对视图产生任何影响。谁能解释一下为什么?

你的风格应该是这样的:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

父主题应来自Theme.MaterialComponents

如果您想在预览中查看它,请单击 select 其他选项,如下图所示:

android:theme="@style/Theme.MaterialComponents"

将此行添加到您的 Material 按钮。

确保删除属性:

android:background="@color/white"

如果需要使用背景,请将其替换为app:backgroundTint

app:backgroundTint="@color/white"