3

在屏幕的布局内,我正在尝试从带有圆角的新材质组件中实现 MaterialButton

<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"/>

但是在预览屏幕上,圆角是不可见的——这个属性对视图没有任何影响。谁能解释我为什么?

4

3 回答 3

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

将此行添加到您的材质按钮。

于 2020-02-19T06:47:46.760 回答
2

确保删除该属性:

android:background="@color/white"

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

app:backgroundTint="@color/white"
于 2020-11-19T08:26:20.877 回答
-2

你的风格应该是这样的:

<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

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

在此处输入图像描述

于 2018-11-12T22:22:34.043 回答