skip to Main Content

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


  1. 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" />
    
    Login or Signup to reply.
  2. 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"/>
    
    Login or Signup to reply.
  3. 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));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search