views:

33

answers:

1

Hi,

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?

A: 

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.

kcoppock
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