按钮颜色.setBackgroundColour()延迟闭合


if(characterArray[i] == '4')
{
    btn3.setBackgroundColor(0xFF0000FF);//bright blue
    timeDelay(300);
    btn3.setBackgroundColor(0xFF00008B);// dark blue
}

当按钮单击时,我正在尝试更改按钮的颜色,并在延迟后返回其原始颜色。我可以让它更改颜色,但是如果我使用延迟,然后将其返回到原始内容,它似乎会跳过其变为新颜色的部分。我正在使用.setBackgroundColor()。任何帮助。

handler.postDelayed(r, 5000);
final Runnable r = new Runnable() {
    public void run() {
        changeToOrigColor();
    }
};

颜色在五秒钟内变化。如果您正在寻找颜色的逐渐变化,请参阅动画!

public void timeDelay(long t) {
    try {
        Thread.sleep(t);
    } catch (InterruptedException e) {}
} char[] characterArray = strIncom.toCharArray();
                    for (int i = 0; i < characterArray.length; i++)
                    {
                        if(characterArray[i] == '1')
                        {
                            btn0.setBackgroundColor(Color.YELLOW);//bright yellow
                            colour0();
                            timeDelay(1000);
                            //btn0.setBackgroundColor(0xFFFFD700);//dark yellow
                        }
                        if(characterArray[i] == '2')
                        {
                            btn1.setBackgroundColor(0xFF7CFC00);//bright green
                            colour1();
                            timeDelay(1000);
                        }
                        if(characterArray[i] == '3')
                        {
                            btn2.setBackgroundColor(0xFFFF0000);
                            colour2();
                            timeDelay(1000);
                        }
                        if(characterArray[i] == '4')
                        {
                            btn3.setBackgroundColor(0xFF0000FF);//bright blue
                            colour3();
                            timeDelay(1000);
                        }
                    }

                    break;
            }
        }
    };                                                                                         

最新更新