I have a plain ImageView
object colorSquare
.
It is straightforward to set the color of the object by calling.
colorSquare.setBackgroundColor(color);
But how do I do the reverse, i.e. retrieve the color of the ImageView background?
How do I change the color of my tint in ImageView? Tint color means when we want to change the color of the image while rendering in ImageView. In XML is very easy to change tint color by just setting up the attribute android:tint="" in the ImageView tag, as shown in the following example.
What u can do is
get ColorDrawable from ImageView.
ColorDrawable drawable = (ColorDrawable) colorSquare.getBackground();
now
drawable.getColor()
will give u the Color.
This will work only if u have set the Color or else u will get ClassCastException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With