Adnan Ahmad Khan
Adnan Ahmad Khan

Reputation: 644

How to Remove Background Color of Button to get Default Background in Android

I am Working on a Test Application in which every question is presented with Four options [those options are via Button]. When a User clicks a button and his answer is correct then background of that button Turns Green, and if his answer is incorrect it turns Red. What i want to do is Reset the Button Background on Next Question.

After Searching a lot of People have asked the same Question and Accepted the answer as

  btnChoiceB.setBackgroundColor(0x00000000);

But the problem is, it turns the Whole Button Transparent, which is not my requirement. I Just want the default color Back.

Do Not Suggest

btnChoiceB.setBackgroundColor(null);

as it does not work.

This is What i want Back. This is What i want Back.

UPDATE/ANSWERED

As Suggested by quick learner,

btnChoiceB.setBackgroundResource(android.R.drawable.btn_default);

worked pretty cleanly.

Upvotes: 4

Views: 8210

Answers (4)

Prakash
Prakash

Reputation: 47

themes.xml Write this change default themes style name Theme.AppCompat.Light.NoActionBar

Upvotes: 0

Quick learner
Quick learner

Reputation: 11477

Try this

btnChoiceB.setBackgroundResource(android.R.drawable.btn_default);

Upvotes: 5

user7320356
user7320356

Reputation:

The term you used was wrong it should be SetImageResources(R.drawable.image); Your image can just be the color and the button text will hover it.

Upvotes: 0

razgraf
razgraf

Reputation: 221

You could try using android:backgroundTint . That, or try to look over this answer here.

Upvotes: 1

Related Questions