Issue
Ive seen a few things on here about rounded corners and colored backgrounds but nothing that quite suits my needs.
The way that I have seen to make a rounded corner button (which works) is to create a xml file in the drawable folder, then put something like such.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/Blue"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
and thats great, for one button. is there a way I can combined four colors into one xml file so i dont have to make four separate ones? I want them all to have 10dp radius like this blue button, but each have their own respective colors.
what im asking is the only way that i can get the rounded edges is to say in my main xml file is android:background="@drawable/round
which would be fine if i could say that and then android:background="@color/Blue"
but since i cant make to calls to android:background
I had to name the color in this drawable xml file. SO now i dont know how to change the color dynamically in this round.xml file
regards.
Solution
You can define one xml and change button colors dynamically by following:
GradientDrawable sd = (GradientDrawable) button1.getBackground();
sd.setColor(Color.BLUE);
GradientDrawable sd1 = (GradientDrawable) button2.getBackground();
sd1.setColor(Color.RED);
Answered By - vipul mittal
Answer Checked By - Katrina (JavaFixing Volunteer)