Attribute app:cornerRadius doen't work for the MaterialButton

Viewed 2662

Inside screen's layout I'm trying yo implement MaterialButton from new Material Components with rounded corners

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

But on preview screen rounded corners are not visible - this attribute doen't bring any effect on view. Can anybody explain me why?

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

Add this line line to your Material button.

Make sure to remove the attribute:

android:background="@color/white"

Or replace it with app:backgroundTint if you need to use a background

app:backgroundTint="@color/white"

Your style should be like this:

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

The parent theme should come from Theme.MaterialComponents

If you want to see it in preview, click and select other options like below image:

enter image description here

Related