How to reset a button's background color to default?

Android

Android 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());

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioncoolcool1994View Question on Stackoverflow
Solution 1 - AndroidSeanView Answer on Stackoverflow
Solution 2 - AndroidIvoView Answer on Stackoverflow
Solution 3 - AndroidSahil PaudelView Answer on Stackoverflow
Solution 4 - AndroidOmid FastView Answer on Stackoverflow