Possible Duplicate:
How to remove ImageButton's standard background image?
I've set a custom background to a Button
. Now I want to revert this change and display the default background of the Button
again. How can I do this?
Possible Duplicate:
How to remove ImageButton's standard background image?
I've set a custom background to a Button
. Now I want to revert this change and display the default background of the Button
again. How can I do this?
You can use android:background="@null"
for your Button
.
or button.setBackgroundResource(0);
or button.setBackgroundDrawable(null);
By programatically, you can do something like,
button.setBackgroundDrawable(null);
button.setBackgroundResource(0);
Finally I got solution of my problem btn.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
This makes my button's background as it has by default.
One solution is simply to remember which Drawable you had as the background before you set it to a custom one, e.g. save it in onCreate()
.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
button = (Button) findViewById(R.id.yourbutton);
defaultButtonBackgroundDrawable = button.getBackground();
// set a custom background here, or somewhere else.
// Just make sure that the default one is saved before you modify it.
}
where defaultButtonBackgroundDrawable
is a member variable of your activity and button
keeps a reference to your button. This way you can restore the default background pretty easily by doing
button.setBackgroundDrawable(defaultButtonBackgroundDrawable);