Reputation: 15734
I need to see if there is a way where I can test for what background a button
has. For example, here is my pseudo code:
if (button background is `R.drawable.black`) {
button.setBackground(to R.drawable.white)
}
Is there a way that this if
statement can be done? I know how to SET backgrounds, just curious on the test portion.
Upvotes: 2
Views: 96
Reputation: 16398
In your case, I believe that tags would be useful. Try this:
//When you set the button:
btn.setBackgroundResource(R.drawable.black);
btn.setTag(R.drawable.black);
//When you re-set the button:
if(btn.getTag().equals(R.drawable.black)) {
btn.setBackgroundResource(R.drawable.white);
btn.setTag(R.drawable.white);
}
Upvotes: 1
Reputation: 18151
There is a getBackgroud
method
Drawable buttonBackground = button.getBackground();
Upvotes: 1