0

I have a button and I want to highlight it for a brief time. For e.g. it's a red button and it should be orange for a second and then turn red again.

My code for this looks like the following:

button.setBackgroundResource(R.color.orange);    //highlight value
button.invalidate();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e1) {
            } 
button.setBackgroundResource(R.color.red);   //old value
button.invalidate();

This doesn't work. The current thread pauses for 3 seconds, but the background image is not changed before. In fact it only changes afterwards to the "old value".

How can i build this highlight feature?

Daniel
  • 539
  • 1
  • 6
  • 7

1 Answers1

0

You could instead try something like this answer to add the highlight. You could play around with a few of the different PorterDuff modes and see which results you like.

Community
  • 1
  • 1
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • This doesn't work. It still only changes the color to the one specified in the "old value" line. I think it's some kind of threading issue, cause i pause the UI thread which didn't refresh the background when i call the first invalidate, then pauses and then gets the new (old value) background and displays this – Daniel Sep 23 '10 at 18:35