gpt4 book ai didi

java - 按钮闪光

转载 作者:行者123 更新时间:2023-12-01 13:02:06 25 4
gpt4 key购买 nike

嗨,我正在尝试让按钮闪烁,我尝试用循环更改背景,但运气不佳,没有任何建议,谢谢

int count = 0;
while (count < 10000) { // test: boolean test within (..)
if (count % 2 != 0) {
helpt.setBackgroundColor(getResources().getColor(R.color.Blue));
}
else {
helpt.setBackgroundColor(getResources().getColor(R.color.Red));
}
count = count + 1;
}

最佳答案

这将每秒改变颜色:

int count = 0; //Declare as instance variable    
Activity activity; //Declare as instance variable

//Inside onCreate()
activity = this;
new Timer().schedule(new TimerTask() {

@Override
public void run() {

activity.runOnUiThread(new Runnable() {
public void run() {
if (count < 10000) {
if (count % 2 != 0) {
helpt.setBackgroundColor(getResources()
.getColor(android.R.color.black));
} else {
helpt.setBackgroundColor(getResources()
.getColor(android.R.color.white));
}
count = count + 1;
}
}
});

}
}, 0, 1000);

关于java - 按钮闪光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23448787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com