-1
我想编写简单的应用,改变continiously它的颜色从红到蓝在时间指定的时间间隔,所以它模拟警笛。但我不知道代码如何使应用程序改变它的颜色。Android应用程序 - 警笛模拟器
这里就是我试过,当然它不能工作...
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);
}
}
}
作品,谢谢! ; ) – Hoymm