Reputation: 885
I want to change my button background at RUNTIME
I know how to add a custom background to a button, but
How can I change it to borderlessButtonStyle? in the xml was easy, I used:
style="?android:attr/borderlessButtonStyle")
How can I switch back to the default background? The following is not what I want (apperantly it is not the default used in Jelly Bean)
changeableButton.setBackgroundResource(android.R.drawable.btn_default);
Thanks for your help
Upvotes: 2
Views: 5283
Reputation: 61
There is a simple answer to this problem:
button.setBackgroundResource(R.drawable.backround);
you can also change back to your default backround by using an if statement and repeating the above statement by just changing the "backround" resource to your default resource. Btw thanks for A2A.
Upvotes: 0
Reputation: 885
I actually found a solution
You can save the initial background of your button in a Drawable object
Drawable d = button.getBackground();
Now you can modify your button's background as you wish
button.setBackgroundResource(R.drawable.custom_button);
Than you can modify it back
button.setBackgroundDrawable(d);
Upvotes: 5