I have made a rounded button in Android studio, so for a rounded button, I added a new XML file and have used that file as a background for the button. The background color by default is purple I want to make it white. I made changes in XML (the color is now set to white), but still, when I check it in design it still looks purple.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<stroke android:color="@color/white" android:width="1.5dp" />
<corners android:radius="25dp"/>
</shape>
Button Code:
<Button
android:id="@+id/button2"
android:layout_width="123dp"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="@drawable/rounded2"
android:backgroundTint="#F4F3F3"
android:text="Message"
android:textColor="#090808"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
3
Answers
use androidx.appcompat.widget.AppCompatButton tag instead of Button in your xml file.
You can use
MaterialButton
instead ofButton
Using
MaterialButton
you can add stroke, background color using attributes ofMaterialButton
instead of creating separatedrawable
file.For Button Stroke:
For Button Radius:
For Button Background:
MaterialButton Code:
for XML try below line and see if its working fine or not .
for kotlin try below code.