@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
take = getIntent();
levelone = take.getIntArrayExtra("level1");
take = getIntent();
leveltwo = take.getIntArrayExtra("level2");
take = getIntent();
levelthree = take.getIntArrayExtra("level3");
colors[0] = (R.drawable.blue1);//Suppose to give integer value for the colors
colors[1] = (R.drawable.purple1);
colors[2] = (R.drawable.yellow1);
colors[3] = (R.drawable.green1);
colors1[0] = (R.drawable.blue);//Suppose to set the colors back to origin
colors1[1] = (R.drawable.purple);
colors1[2] = (R.drawable.yellow);
colors1[3] = (R.drawable.green);
purple = findViewById(R.id.purplee); //1
green = findViewById(R.id.greenn);//2
yellow = findViewById(R.id.yelloww);//3
blue = findViewById(R.id.bluee);//4
for (int i = 0; i < btn.length; i++) {
buttons[i] = findViewById(btn[i]);
buttons[i].setOnClickListener(this);
}
buttons[1].setBackgroundResource(colors[1]);//purple Butttons[1]
buttons[2].setBackgroundResource(colors[2]);//Yellow Buttons[2]
buttons[3].setBackgroundResource(colors[3]);//Green Buttons[3]
buttons[0].setBackgroundResource(colors[0]);//Blue Buttons[0]
// Blue Buttons[0],purple Butttons[1] ,Yellow Buttons[2],Green Buttons[3]
//colors[0]==Blue ,colors[1]==purple,colors[2]==Green,colors[3]==Yellow
//Set background button color}
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
/* buttons[0].setBackgroundColor(Color.BLUE); //Suppose to change the color to the primary color*/
for(int i=0;i<levelone.length;i++)
{
buttons[1].setBackgroundResource(colors[1]);
}
}
}, 1000);//Set delay between changes of colors
我想知道如何设置延迟来更改按钮的背景颜色,例如大约1秒钟后再返回原点,我试图做类似的事情,但是没有用,我不知道应该怎么做工作,谢谢帮手!