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

43

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
asked on Stack Overflow Feb 10, 2013 by coolcool1994

3 Answers

59

use:

btn.setBackgroundResource(android.R.drawable.btn_default);
answered on Stack Overflow Feb 10, 2013 by Sean • edited Feb 10, 2013 by Sean
13

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.

answered on Stack Overflow May 17, 2016 by Ivo • edited May 17, 2016 by Ivo
5

Nobody mentioned TRANSPARENT use it like this

findViewById(R.id.button_id).setBackgroundColor(Color.TRANSPARENT);

Thank me later

answered on Stack Overflow Mar 21, 2017 by Sahil Paudel • edited Apr 4, 2017 by Sahil Paudel

User contributions licensed under CC BY-SA 3.0