I want to change the background image of a button when clicked or focused.
This is my code:
Button tiny = (Button)findViewById(R.id.tiny);
tiny.setOn
To change the button background we can follow 2 methods
In the button OnClick, just add this code:
public void onClick(View v) {
if(v == buttonName) {
buttonName.setBackgroundDrawable
(getResources().getDrawable(R.drawable.imageName_selected));
}
}
2.Create button_background.xml in the drawable folder.(using xml)
res -> drawable -> button_background.xml
Now set the above file in button's background file.
(or)
Button tiny = (Button)findViewById(R.id.tiny);
tiny.setBackgroundResource(R.drawable.abc);
2nd method is better for setting the background fd button