-1

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 Answers3

0

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" />
Alireza Barakati
  • 1,016
  • 2
  • 9
  • 23
  • yes, it works now, but now the button is not in rounded format anymore. I have made separate XML to make the button round. and have used that XML as the background of the button. but the button is not inn rounded anymore – zulkefal mohammadzai Feb 22 '22 at 12:58
  • @zulkefalmohammadzai then just remove android:backgroundTint="#F4F3F3" – Alireza Barakati Feb 22 '22 at 13:02
0

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"/>
Android Geek
  • 8,956
  • 2
  • 21
  • 35
0

for XML try below line and see if its working fine or not .

   android:drawableTint="@color/white"    
   android:tint="@color/section_arrowup_color"

for kotlin try below code.

    DrawableCompat.setTint(arrowSign.getDrawable(),
    ContextCompat.getColor(arrowSign.getContext(), R.color.orange));

    DrawableCompat.setTint(button.getBackground(),
    ContextCompat.getColor(button.getContext(), R.color.darkBlack));
Atif AbbAsi
  • 5,633
  • 7
  • 26
  • 47