Alex Rivera | Logout

Getting the background color of an ImageView

Asked 2012-02-18T07:43:36.177
9

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?

Edit
Report

1 Answer

18

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

answered 2012-02-18T07:57:12.763

Your Answer