If you want to change it randomly you can use this one
private void changeColors () {
switch (new Random().nextInt([Number Of options])) {
case 0:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 1:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 2:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 3:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 4:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 5:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
}
}
If you want to set them in an order you could use this, setting a counter in the on-click listener defining an n outside of it;
n=0;
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeColors(n);
n + 1;
}
});
private void changeColors () {
switch (n) {
case 0:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 1:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 2:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 3:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 4:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
case 5:
textView.setTextColor([COLOR]);
layout.setBackgroundColor([COLOR]);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…