0

What can I do to change the drawable of a background switching between two buttons. For example, I want that when I click button_1 the drawable change to the image "background_1" and when I click button_2, it changes to the image "background_2"

Thanks to all of you!

PD: Sorry for my bad english, i'm catalan

2 Answers2

0

You can use

button1.setOnClicklistener(this);
button2.setOnClicklistener(this);

public void (View view){
    If(view.getId==R.id.button1){
your_root_view.setImageResource(R.drawable.background_1;
  } else {
     your_root_view.setImageResource(R.drawable.background_2;
     }
} 

Make sure your activity implements View.OnClickListener

0

If you want to change your button background:

button1.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        button1.setBackGroundResource(R.drawable.background_1);
    }
 });

button2.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        button2.setBackGroundResource(R.drawable.background_2);
    }
 });
Juan Cruz Soler
  • 8,172
  • 5
  • 41
  • 44