Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the background color of an ImageView

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?

like image 844
CjS Avatar asked Feb 18 '12 07:02

CjS


People also ask

How do I change the color of an ImageView tint XML?

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.


1 Answers

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

like image 70
Vivek Khandelwal Avatar answered Sep 20 '22 20:09

Vivek Khandelwal