Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button changeColorsButton = findViewById(R.id.change_colors_button);
- final LinearLayout linear1 = findViewById(R.id.linear1);
- final LinearLayout linear2 = findViewById(R.id.linear2);
- final LinearLayout linear3 = findViewById(R.id.linear3);
- final LinearLayout linear4 = findViewById(R.id.linear4);
- final LinearLayout linear5 = findViewById(R.id.linear5);
- final Random random = new Random();
- changeColorsButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- linear1.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
- linear2.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
- linear3.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
- linear4.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
- linear5.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement