Libgdx change TextButton bg alpha - libgdx

I have this textbuttons where the user can change the colors, now I want the user to be able to change the alpha too.
When I change the alpha of the font textbutton it only affect the font alpha wich is great. button.getStyle ().fontColor = newColorWithLowAlpha
But when I change the alpha of the button it affects the font alpha too.button.setColor(newColorWithLowAlpha)
Is there a way to change the button alpha without changing the alpha of the text? Thanks

Related

LibGDX BitmapFont Markup Alpha Value

Alright, so I have a bitmap font with markup enabled. The problem is, I need to set the global alpha value for a whole string of text without setting an individual alpha value for each color code.
For example, I have...
"[#0000ff]this is blue, [#990000]this is red"
I'd like the font text to fade into the background by setting an alpha value. Is there any way to do this without manually parsing color codes and sticking an alpha value into the brackets?
I've also tried adding custom colors with Colors.put(..), but that gets really clunky, as I have to set the alpha value to each color I'm using, with each line of text that I am drawing.
You'll need to use the BitmapFontCache class.
So for example, say your code currently looks like this...
font.drawWrapped(batch, text, x, y, wrapWidth, alignment);
Replace it with the following and you can control the alpha in the way you require...
BitmapFontCache cache = font.getCache();
cache.clear();
TextBounds bounds = cache.addMultiLineText(text, x, y, wrapWidth, alignment);
// This is the useful bit!
cache.setAlphas(alphaTransparency);
cache.draw(batch);
Note - If you're using distance field fonts then the shader most people use for them doesn't support alpha, but it's easy to fix it so it does. Let me know if you hit that problem.

Change font color of TextButton on click?

I've read some tutorials and documentation on scene2d's UI capabilities, but I can't quite figure out how the skins work. I simply want a TextButton that changes color when pressed. I managed to get the background of the TextButton to change, but that's not what I wanted. It should have no background.
I would be very grateful if anyone could provide an example of how this could be done. It seems very simple, so I think I'm missing something obvious here. If a skin is involved, please write it programmatically.
Thank you.
Turns out it was as simple as I thought, it just didn't work when I tried it the first time.
When defining the TextButtonStyle you can assign downFontColor the color you want your text to be while it is being pressed. You can also assign checkedFontColor the color you want the text toggle between when pressed.
Example:
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.font = someBitmapFont;
textButtonStyle.fontColor = Color.WHITE;
textButtonStyle.downFontColor = Color.BLACK;
//Optional color to toggle between when pressed
textButtonStyle.checkedFontColor = Color.GREEN;
final TextButton textButton = new TextButton("Text", textButtonStyle);
This will produce a white TextButton that turns black when it is pressed. When the mouse/touch is released it'll either turn green or white, depending on the state of the toggle.
You can also tint it, but the effect depends on the base color (if it is white, then it works perfectly, else it depends). Anyway, it's done like this:
button.getLabel().setColor(myColor);

change button color action script 3

btnPlanet.mouseEnabled = false;
btnPlanet.mouseChildren = false;
i have button and it's called btnPlanet, i want to change button color when they are disabled, but the button contain text, that if i change button color using colorTransform, it make my text dismissed, and filled with color that i use from colorTransform, can i change only color of shape in button without change text color? or make it grayscale at least? thank you, i'm sorry if i have bad grammar english
Apply alpha/colorTransform/whatever to everything EXCEPT text field.
Is it your own button or you're using some kind of component?
If it's your own I bet you have something like background for shape and TextField on top of that.
If it's a component I'm pretty sure you should be able to access it as well.
that's not hard.set instance name of your shape in your button for example myShape. Then write:
btnPlanet.myShape.transform.colorTransform=new ColorTransform(your colortransform settings)

flex - how to set the background color of a spark check box text label?

I have a simple spark mxml check box and I want to change the background color via actionscript. I have searched and tried many suggestions, including using setStyle with 'background-color', 'chromeColor', symbolColor and others like this - the only thing that worked at all is chromeColor, which colored the box but not the text or background:
insUpdatedCB.setStyle('chromeColor','yellow');
I also tried using text format like this:
var myTf:TextFormat = new TextFormat();
myTf.size = 16;
myTf.color = 0xFF0000;
insUpdatedCB.setStyle("textFormat", myTf);
also did not work
how can I set the label/text background color?
If you want to change the background color of the spark checkbox, then you have to apply a custom skin for it. Make a new Custom skin by making a copy of default checkboxSkin for spark checkbox, and then change the background color of the label in the Custom Skin.

assign a variable to font color in JLabel

I want to change the color of text in the JLabel. For this purpose, I used HTML format but my problem is how can I assign a variable to the font color? Here is a sample code:
`
ArrayList<Color> myColor=new ArrayList<Color>();
...
for(int i=0;i<myColor.size(); i++){
myLabel.setHorizontalTextPosition(JLabel.LEFT);
myLabel.setHorizontalAlignment(JLabel.LEFT);
myLabel.setText(String.format("<html>%s<font color=:"myColor.get(i)+">%s</font></html>", myLabel.getText(),"new text");
} `
When I want to run this code, the color is considered black for all of text but I want to assign different color to different text in JLabel.
It should be better to mention that I had some text in that JLabel. Using setForeground commend results in changing the color of other text. I want to change the color of one text while others have remained in their own color and because of that I used HTML format.
Any help will be really appreciated!
Try using setForeground(). This method will set the font color of your label. For example myLabel.setForeground(Color.ORANGE); will set the font color to orange.