Advertisement
Sketchware

Button muda de cor

Jan 9th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. final int[] colors = {Color.parseColor("#008DCD"), Color.parseColor("#FFFF5722")}; // Define as cores que serão alternadas
  2.  
  3. button.setOnClickListener(new View.OnClickListener() {
  4. int i = 0;
  5. @Override
  6. public void onClick(View v) {
  7. Button button = (Button) v;
  8. GradientDrawable gd = new GradientDrawable();
  9. gd.setCornerRadius(38);
  10. gd.setColor(colors[i % 2]); // Alterna entre as duas cores definidas
  11. button.setBackground(gd);
  12. i++;
  13. }
  14. });
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement