androidcolorsimageviewgradientdrawable

Gradient drawable getColor() method for API 16 or less


So I need to change the color an ImageView programmatically, and getBackGround returns a GradientDrawable which has a setColor method but no getColor, at least not for API 16 or lower. So my question is: is there like a support library version of the GradiantDrawable ?. If there is, how can I use it considering that I'm using an xml drawable that has a layer-list as the root and I only want to change one of the layer's color and then be able to retrieve the color later.


Solution

  • Use a ColorDrawable for that layer instead. If necessary, you can set the drawable for a given layer at runtime using layerDrawable.setDrawableByLayerId(), but you should only have to do that at most once.