Advertisement
Sketchware

Cores randomicas em 5 lineares

Jan 21st, 2023
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. Button changeColorsButton = findViewById(R.id.change_colors_button);
  2. final LinearLayout linear1 = findViewById(R.id.linear1);
  3. final LinearLayout linear2 = findViewById(R.id.linear2);
  4. final LinearLayout linear3 = findViewById(R.id.linear3);
  5. final LinearLayout linear4 = findViewById(R.id.linear4);
  6. final LinearLayout linear5 = findViewById(R.id.linear5);
  7. final Random random = new Random();
  8.  
  9. changeColorsButton.setOnClickListener(new View.OnClickListener() {
  10.     @Override
  11.     public void onClick(View view) {
  12.         linear1.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
  13.         linear2.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
  14.         linear3.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
  15.         linear4.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
  16.         linear5.setBackgroundColor(random.nextInt(2) == 0 ? Color.RED : Color.BLUE);
  17.     }
  18. });
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement