I have the following
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="20dp"/>
</shape>
Which I set as a background to my layout.
I can set the color using the following
root.getBackground().setColorFilter(Color.parseColor("#ab2233"), PorterDuff.Mode.SRC_ATOP);
However this sets a solid color. I would like to set a gradient color instead and then pass this color around for other backgrounds. Is there a way I can set a gradient? I know there is a solution on SO using canvas but I was hoping to avoid it especially that I want to keep the rounded corners and any other shape features.
Is there a way I can set Color gradient dynamically? I thought about introducing a gradient in a shape but I need the color to be dynamic.
Any solutions?
Thanks
Edit: This is not a duplicate as I specifically asked to keep using the xml but just tweak the color value