gpt4 book ai didi

android - 连续更改android按钮颜色

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:31 25 4
gpt4 key购买 nike

我的应用程序中有一个简单的按钮。
我想做以下事情:
当应用程序运行时,按钮的颜色不断变化(例如每 3 秒),无需任何触摸或聚焦,以吸引客户点击它的眼睛。
有什么办法吗?

最佳答案

使用下面的代码:

Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run()
{
int rnd = (int)(Math.random() * 4);
if(rnd==0)
btn.setBackgroundColor(Color.BLUE);
if(rnd==1)
btn.setBackgroundColor(Color.RED);
if(rnd==2)
btn.setBackgroundColor(Color.GREEN);
if(rnd==3)
btn.setBackgroundColor(Color.YELLOW);

btn.invalidate();
handler.postDelayed(runnable, 3000);
}
};
handler.postDelayed(runnable, 3000);

关于android - 连续更改android按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32413068/

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