Search code examples
androidandroid-studioandroid-buttonmaterial-componentsmaterial-components-android

Android Styling: Setting border to 0sp does not remove border radius of Material Button


I am trying to style a button such that it does not have a border radius. I have tried setting the radius property to 0sp, but that has not worked. Below is my code and a screenshot of the resulting button, which still has rounded corners.

<com.google.android.material.button.MaterialButton
        android:id="@+id/material_text_button"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:textAppearance="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:layout_marginTop="11sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:radius="0sp"
        android:text="#1 Lorem Ipsum"
        android:textSize="16sp"/>


Solution

  • For the corner radius use the app:cornerRadius attribute:

    <com.google.android.material.button.MaterialButton
        app:cornerRadius="0dp"
        ../>
    

    Outlined/Filled result:

    enter image description here

    About your layout, use dp instead of sp in these dimensions:

        android:layout_marginTop="11sp" //dp
        android:radius="0sp"  //dp and app:cornerRadius
    

    and this style @style/Widget.MaterialComponents.Button.OutlinedButton shouldn't be used in android:textAppearance.