简体   繁体   English

libdgx如何设置TextButton的样式?

[英]libdgx how to set style of TextButton?

Using the uiskin.json by default 默认使用uiskin.json

It contains 它包含

com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: { font: default-font, fontColor: white }
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
default: { down: default-round-down, up: default-round, font: default-font, fontColor: white     },
toggle: { down: default-round-down, up: default-round, checked: default-round-down, font:     default-font, fontColor: white, downFontColor: red }
},

-- -

skin = new Skin(Gdx.files.internal("data/uiskin.json"));
TextButton button = new TextButton("my button",skin);

if clicked, it will change color using button.setColor(Color.RED); 如果单击,它将使用button.setColor(Color.RED);更改颜色button.setColor(Color.RED); This works well. 这很好。

if clicked again, I want it to change back to the default style. 如果再次单击,我希望它改回默认样式。 I wrote the following but it causes an error 我写了以下内容,但会导致错误

button.setStyle(new TextButton.TextButtonStyle());

The error is: 错误是:

FATAL EXCEPTION GLThread 2812
java.lang.IllegalRuntimeException: Missing LabelStyleFont

I have the files default.fnt and default.png in my assets folder already. 我的资产文件夹中已经有文件default.fnt和default.png。 Please enlighten me! 请赐教!

您不需要做TextButton.getStyle()来获取样式吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM