Each button represents something clickable, which has a color stored in the database that a user can configure. The background of the button is the <shape>
that follows.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="#000" />
<corners android:radius="5dp" />
<gradient android:startColor="#FFF"
android:centerColor="#FFF"
android:endColor="#666"
android:angle="315" />
<padding android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>
I'd like to get at the <gradient>
element — specifically the startColor
centerColor
and endColor
attributes. I can do this:
button.getBackground().setTint(theColor);
But that seems to wipe out the stroke and gradient.
Is this possible? Is there a better way?
try below snippet, give it a try