0

I have a layout with different views. One of the views has a background color set to android.R.color.holo_green_light

Inside a click handler, how can I check if the clicked element has a background set to android.R.color.holo_green_light ?

I know for for APIs > 13 I can get view.getBackground().getColor(), but how to do it for APIs below 13 ?

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Running Turtle
  • 12,360
  • 20
  • 55
  • 73
  • Hi, I don't if it can help but this solution is avalaible from API 11 which maybe lower as the one you're using (you did not specified) : http://stackoverflow.com/a/14779461/2545832 – Laurent Meyer Sep 29 '14 at 15:38
  • View.getBackground() returns a Drawable. There is no method getColor() for Drawable. – Pedro Oliveira Sep 29 '14 at 15:38

1 Answers1

0

If you know that the background of the view is a Color.

You can get the drawable and cast it to a ColorDrawable:

ColorDrawable viewColor = (ColorDrawable) view.getBackground();
int colorId = viewColor.getColor();

That works on Android API 11

rastadrian
  • 1,025
  • 1
  • 10
  • 17