Advertisement
Sketchware

Deixa o button1 inativo 3 segundos e deixa ele vermelho

Mar 7th, 2023
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. // Salva a cor original do botão
  2. final ColorStateList originalColors = button1.getBackgroundTintList();
  3.  
  4. // Define a nova cor do botão
  5. int newColor = Color.RED; // Defina a nova cor aqui
  6. button1.setBackgroundTintList(ColorStateList.valueOf(newColor));
  7.  
  8. button1.setClickable(false);
  9. button1.setEnabled(false);
  10.  
  11. new Handler().postDelayed(new Runnable() {
  12.     @Override
  13.     public void run() {
  14.         // Reverte a cor do botão de volta para a original
  15.         button1.setBackgroundTintList(originalColors);
  16.        
  17.         button1.setClickable(true);
  18.         button1.setEnabled(true);
  19.     }
  20. }, 3000); // 3000ms = 3 segundos
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement