'cornerRadius not working with backgroungTint

I am a beginner in android dev. I am making a calculator in which i want to add round button using corner Radius. the problem is that it is working fine when i donot set background tint as shown below

<Button
    android:id="@+id/button_7"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="7"
    android:textColor="#000000"
    app:cornerRadius="20dp" /> 

image

but when i set background tint it does not work

<Button
    android:id="@+id/button_7"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="7"
    android:textColor="#000000"
    app:cornerRadius="20dp"
    android:background="#E3E3E3"
    app:backgroundTint="#E3E3E3"/>

image

What should i do? thanks!



Solution 1:[1]

Try this with more customization with button as per your requirement.

<androidx.appcompat.widget.AppCompatButton
    android:id="@+id/btn_scan_qr"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/rounded" //CREATE rounded.xml in res/drawable 
    android:text="7"
    android:textSize="15sp" />

rounded.xml in res/drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- you can use any color you want I used here gray color-->
    <solid android:color="#ABABAB" />

    <corners
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" />
    <size
        android:width="10dp"
        android:height="1dp" />
</shape>

Solution 2:[2]

try this

  <com.google.android.material.button.MaterialButton
    android:id="@+id/button_7"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="7"
    android:textColor="#000000"
    app:cornerRadius="20dp"
 />

for using backgroud color just use app:backgroundTint="#334567". don't use background .. you are facing the problem because you have used both. just used one.

enter image description here

Solution 3:[3]

Just remove android:background in the Button.

<Button
    android:id="@+id/button_7"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="7"
    android:textColor="#000000"
    app:cornerRadius="20dp"
    app:backgroundTint="#E3E3E3"/>

Using a custom background with android:background the default MaterialShapeDrawable is not used and some features like stroke, shapeappearance (rounded corners), ripple, are not set (since they are related to the MaterialShapeDrawable)and you have to provide them with your custom background.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sandesh KhutalSaheb
Solution 2
Solution 3 Gabriele Mariotti