1

Here I am writing the code of XML That I am using to change the background of button.

roundbutton2.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#eea0e5ee"/>
    <corners android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topRightRadius="10dp"
        android:topLeftRadius="10dp"/>
</shape> 

Buttons snippet

<Button
    android:layout_width="125dp"
    android:layout_height="55dp"
    android:text="Clear"
    android:id="@+id/bt_clear"
    android:layout_marginLeft="55dp"
    android:layout_marginRight="30dp"
    android:textColor="#FFFFFF"
    android:textSize="25dp"
    android:textAllCaps="false"
    android:background = "@drawable/roundbutton2"/>

<Button
    android:layout_width="125dp"
    android:layout_height="55dp"
    android:text="Proceed"
    android:textColor="#FFFFFF"
    android:textSize="25dp"
    android:id="@+id/bt_proceed"
    android:textAllCaps="false"
    android:background = "@drawable/roundbutton2"/>

For first i want the #EE494D4E color and for second button i want #eea0e5ee.How can do this. I want the different color for both button using same XML file. Please Tell me about this.Thanx

dev
  • 11
  • 1
  • 6

1 Answers1

0

In your roundbutton2.xml you are directly setting the color of the shape value to #eea0e5ee which causes your buttons that set it as a background to have that color. What I did was remove the <solid android:color="#eea0e5ee"/> and set the backgroundTint via the xml to your preferred color, like so:

<Button
        android:id="@+id/bt_clear"
        android:layout_width="125dp"
        android:layout_height="55dp"
        android:layout_marginLeft="55dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/roundbutton2"
        android:backgroundTint="#EE494D4E"
        android:text="Clear"

        android:textAllCaps="false"
        android:textColor="#FFFFFF"
        android:textSize="25dp" />

    <Button
        android:id="@+id/bt_proceed"
        android:layout_width="125dp"
        android:layout_height="55dp"
        android:background="@drawable/roundbutton2"
        android:backgroundTint="#eea0e5ee"
        android:text="Proceed"
        android:textAllCaps="false"
        android:textColor="#FFFFFF"
        android:textSize="25dp" />

NOTE: This is just a workaround. I'm not entirely sure if this should be done, or is against best practice. This answer here is my reference. If you still want the default color value of your button to stay, the only way you could achieve changing the color of other buttons is programmatically.

Cheers! :D

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281