【问题标题】:Round Corner is not working in Material Button圆角在材质按钮中不起作用
【发布时间】:2020-11-03 07:25:07
【问题描述】:

我的登录活动布局中有这样的按钮。

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:weightSum="2">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/button_login_activity"
                android:layout_width="0dp"
                android:layout_height="60dp"
                android:layout_weight="1"
                android:text="Login"
                app:cornerRadius="20dp"
                android:background="@color/colorPrimaryDark"
                android:textColor="@color/toolbar_text"
                android:textStyle="bold" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/button_skip_login_activity"
                android:layout_width="0dp"
                android:layout_height="60dp"
                android:layout_marginStart="10dp"
                android:layout_weight="1"
                app:cornerRadius="20dp"
                android:background="@color/colorPrimaryDark"
                android:textColor="@color/toolbar_text"
                android:text="Skip"
                android:textStyle="bold"
                android:layout_marginLeft="10dp" />

        </LinearLayout>

我的风格是这样的

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!--Common Color-->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
        <item name="windowActionBar">true</item>
        <item name="windowNoTitle">true</item>
        <item name="colorSwitchThumbNormal">@color/switch_normal</item>
        <item name="colorControlNormal">@color/switch_normal</item>
        <item name="android:textColorSecondary">@color/switch_normal</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="android:windowDisablePreview">true</item>

    </style>

我有如下依赖

implementation 'com.google.android.material:material:1.2.1'

我已经尝试了很多东西,但无法使其适用于圆角,同样的事情适用于我的另一个项目。让我知道是否有人可以帮助我解决这个问题。 谢谢!

【问题讨论】:

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


    【解决方案1】:

    您必须移除背景:

    android:background="@color/colorPrimaryDark"
    

    使用MaterialButton 不使用自己的MaterialShapeDrawable 作为背景。这意味着形状外观、笔划和圆角等特征将被忽略。

    在您的情况下,使用 app:backgroundTint 属性:

    <com.google.android.material.button.MaterialButton
        app:backgroundTint="@color/colorPrimaryDark"
    

    【讨论】:

      猜你喜欢
      • 2017-07-29
      • 1970-01-01
      • 2017-05-10
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 2019-10-30
      相关资源
      最近更新 更多