I need to be able to change the appearance of a Libgdx Button
when some of my events are triggered.
Here is the declaration of my button:
Button googleButton = new Button(skin.getDrawable("google_sign_in"));
Here are the things I tried:
googleButton.setBackground(skin.getDrawable("google_sign_out"));
googleButton.invalidate();
googleButton.setChecked(true);
googleButton.invalidate();
googleButton.getStyle().up = skin.getDrawable("google_sign_out");
googleButton.invalidate();
I have done a lot of searches but I can't find the answer. Could somebody show me the right way of doing this?
I think the problem is that you're changing the contents of the skin/style after initializing the Button
, but the button object does not reference the style after it has been initialized. I'm also not entirely clear on what you're going for. I assume you want to show a "sign in" button, until the user is signed in, and then you want that button to be a "sign out" button.
The invalidate
method just triggers a re-layout (to re-compute the size/location of the Actor
).
Maybe try forcing the style with setStyle
, like this:
googleButton.getStyle().up = ... whatever;
googleButton.setStyle(googleButton.getStyle());
That said, I think you would be better off having two (?) different Button
objects (one for logging in, and one for logging out). Pack them in a Stack, and just make one or the other invisible (see Actor.setVisible
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With