Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final int[] colors = {Color.parseColor("#008DCD"), Color.parseColor("#FFFF5722")}; // Define as cores que serão alternadas
- Button button = (Button) findViewById(R.id.button1); // Substitua "button1" pelo ID do seu botão
- button.setOnClickListener(new View.OnClickListener() {
- int i = 0;
- @Override
- public void onClick(View v) {
- Button button = (Button) v;
- GradientDrawable gd = new GradientDrawable();
- gd.setCornerRadius(38);
- gd.setColor(colors[i % 2]); // Alterna entre as duas cores definidas
- button.setBackground(gd);
- button.setText(i % 2 == 0 ? "ativado" : "desativado"); // Alterna entre "ativado" e "desativado"
- i++;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement