Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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?

like image 209
coolcool1994 Avatar asked Feb 10 '13 20:02

coolcool1994


People also ask

What is the default background color in android?

By default each activity in Android has a white background. To change the background color, first add a new color definition to the colors.

What should be the color of reset button?

The color BLUE is reserved for functions of urgent significance. Reset push-buttons must be BLUE, WHITE, GREY or BLACK. If these are also used as STOP/OFF buttons, the colors WHITE, GREY or BLACK are preferred, preferably BLACK. GREEN must not be used.

What is the default button color?

By default, a button has a white background and black text. Using the CSS background-color property, we can change a button's background color.


2 Answers

use:

btn.setBackgroundResource(android.R.drawable.btn_default); 
like image 150
Sean Avatar answered Sep 26 '22 00:09

Sean


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.

like image 37
Ivo Avatar answered Sep 24 '22 00:09

Ivo