0

I guess the answer is no, but maybe some guru makes my day: I want to make an ImageView with a gradient, but the thing is that I need many with many different colors. I find it inefficient to create a bunch of drawables with the same shape and everything and the only difference, the EndColor. Do you know any way to give this color to the drawable from the ImageView which is using it as src? (Better if it's from xml). I do NOT want to do it through styles, as creating different styles for just one view would be the same inefficient.

My (very simple) drawable:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="8dp" />
    <gradient android:endColor="@color/pieChartWalking"
        android:startColor="@color/pieChartGradientStart" />
    <size android:width="16dp"
        android:height="16dp" />
</shape>

And this is how I would like to use the drawable:

<ImageView
    android:id="@+id/legend_walking_dot"
    android:layout_width="16dp"
    android:layout_height="16dp"
    android:src="@drawable/myDrawableForGradient"
    my_attribute:startColor="@aColorReference"
    my_attribut:endColor="@anotherColorReference" />

Thanks in advance!

elnezah
  • 187
  • 10
  • You can create the shape and gradient programmatically and then set it as source if I'm not mistaken – Tiago Ornelas Feb 20 '19 at 12:27
  • Check this [link](https://stackoverflow.com/questions/6115715/how-do-i-programmatically-set-the-background-color-gradient-on-a-custom-title-ba). – Surender Kumar Feb 20 '19 at 12:30

0 Answers0