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" />
CodePudding user response:
Add material library to your project with this code:
implementation "com.google.android.material:material:1.4.0"
then in your view change button code to this:
<com.google.android.material.button.MaterialButton
android:id="@ id/button2"
android:layout_width="123dp"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#F4F3F3"
android:text="Message"
android:textColor="#090808"
android:textSize="16sp"
app:cornerRadius="25dp"
app:layout_constraintEnd_toEndOf="@ id/textView3"
app:layout_constraintTop_toBottomOf="@ id/textView3" />
CodePudding user response:
You can use MaterialButton
instead of Button
Using MaterialButton
you can add stroke, background color using attributes of MaterialButton
instead of creating separate drawable
file.
For Button Stroke:
app:strokeWidth="1.5dp"
app:strokeColor="@color/white"
For Button Radius:
app:cornerRadius="25dp"
For Button Background:
app:backgroundTint="#F4F3F3"
MaterialButton Code:
<com.google.android.material.button.MaterialButton
android:id="@ id/button2"
android:layout_width="123dp"
android:layout_height="42dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:backgroundTint="#F4F3F3"
app:strokeWidth="1.5dp"
app:strokeColor="@color/white"
app:cornerRadius="25dp"
android:text="Message"
android:textColor="#090808"
android:textSize="16sp"/>
CodePudding user response:
use androidx.appcompat.widget.AppCompatButton tag instead of Button in your xml file.
<androidx.appcompat.widget.AppCompatButton
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:text="Message"
android:textColor="#090808"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="@ id/textView3"
app:layout_constraintTop_toBottomOf="@ id/textView3" />