【发布时间】:2016-07-03 22:22:45
【问题描述】:
我想编写一个简单的应用程序,它会在指定的时间间隔内不断地将其颜色从红色变为蓝色,因此它可以模拟警笛。但我不知道如何编码,所以应用程序会改变它的颜色。
这是我试过的,当然不行……
LinearLayout mainBackground;
String currentColor = "Blue";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainBackground = (LinearLayout) findViewById(R.id.mainBackgroundID);
while(true) {
sleep(250);
if (currentColor.equals("Blue")) {
currentColor = "Red";
mainBackground.setBackgroundColor(0xFFFF0000);
} else {
currentColor = "Blue";
mainBackground.setBackgroundColor(0xFF0008FF);
}
}
}
【问题讨论】:
标签: java android refresh siren