简体   繁体   English

Android背景颜色变化

[英]android background color changing

I am looking to change my color of my background for a second after a button has been pressed to confirm if the correct button was clicked. 我希望在按下按钮以确认是否单击了正确的按钮后,将背景颜色更改一秒钟。 Afterwords, I want to switch the color back to black, but when I use Thread.sleep() it doesn't change the color before or after the thread sleep. 后记,我想将颜色切换回黑色,但是当我使用Thread.sleep()时,它不会在线程睡眠之前或之后更改颜色。 Any other suggestions? 还有其他建议吗?

background.setBackgroundColor(Color.GREEN);
thread.sleep(1000);
background.setBackgroundColor(Color.BLACK);

Modify your code like this: 像这样修改您的代码:

background.setBackgroundColor(Color.GREEN);
Thread thread = new Thread() {
    @Override
    public void run() {
        try {
            while(true) {
                sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
};

thread.start();
background.setBackgroundColor(Color.BLACK);

Hope it helps!!! 希望能帮助到你!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM