app:cornerRadius doesn't work for MaterialButton
B

3

6
<com.google.android.material.button.MaterialButton
            android:id="@+id/button_tour"
            app:cornerRadius="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="30dp"
            android:layout_gravity="center_horizontal"
            android:text="Take a tour"/>

I added a material button in my android project, when i try to set round corner using app:cornerRadius, i find it doesn't work at all.

Beamends answered 3/12, 2019 at 3:39 Comment(2)
give some height and width to your buttonFuzee
You can write style for thisBrook
I
6

Just use material theme .change parent of AppTheme in styles to some material theme likeTheme.MaterialComponents.Light.NoActionBar.because material components require a material theme.

 <style name="AppTheme.Clinic" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>
Inge answered 3/12, 2019 at 5:40 Comment(1)
That works! Thank you so much! It has confused me a whole day.Beamends
W
0

Try this: add this style for outline material button

   <style name="materialButtonOutlinedStyle" parent="@style/Widget.MaterialComponents.Button.OutlinedButton">
    <item name="cornerRadius">10dp</item>
</style>

then add this style to your button:

    <com.google.android.material.button.MaterialButton
    android:id="@+id/button_tour"
    style="@style/Widget.MaterialComponents.CardView"
    app:cornerRadius="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="30dp"
    android:layout_gravity="center_horizontal"
    android:text="Take a tour"/>
Willawillabella answered 7/7, 2022 at 14:12 Comment(0)
Y
-2

Create a new drawable source such as follows

<shape android:shape="rectangle">

     <corners android:radius="20dp" />

</shape>

and set it as background to your MaterialButton

Yorktown answered 3/12, 2019 at 5:53 Comment(1)
The question is about MaterialButton - this answer is for classic Android ButtonAuraaural

© 2022 - 2024 — McMap. All rights reserved.