How to reset a button's background color to default?
AndroidAndroid Problem Overview
I read a couple of posts but none of them had the working solution.
Once you do
button.setBackgroundColor(0x00000000);
How do you revert the button's background color back to default color?
Android Solutions
Solution 1 - Android
use:
btn.setBackgroundResource(android.R.drawable.btn_default);
Solution 2 - Android
If the background color was set using
btn.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
it can be reset using:
btn.getBackground().clearColorFilter();
In contrast to button.setBackgroundColor()
setting the color this way preserves the button's shape.
Solution 3 - Android
Nobody mentioned TRANSPARENT use it like this
findViewById(R.id.button_id).setBackgroundColor(Color.TRANSPARENT);
Thank me later
Solution 4 - Android
this worked better for me :
Button defbtn=new Button(this);
btn.setBackground(defbtn.getBackground());