I am new to Libgdx and I have been searching for 3 hours to find a way to change text size in text button but I couldn't find any method for this. What should I do to do this.
Table rootTable = new Table();
rootTable.setFillParent(true);
rootTable.setDebug(true, true);
Table menuTable = new Table();
rootTable.add(menuTable).expand().center().right();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
TextButton singlePlayer = new TextButton("Single Player",skin);
TextButton multiPlayer = new TextButton("Multi Player", skin);
TextButton options = new TextButton("Options", skin);
TextButton exit = new TextButton("Exit", skin);
int x = Gdx.graphics.getHeight();
int unit = x / 6;
float scale = unit / singlePlayer.getHeight();
float width = singlePlayer.getWidth() * scale;
menuTable.add( singlePlayer ).size( width,unit).right().row();
menuTable.add( multiPlayer ).size( width,unit).right().row();
menuTable.add( options ).size( width,unit).right().row();
menuTable.add( exit ).size( width,unit).right().row();
使用textButton.getLabel().setFontScale(x, y)
。
Use FreeTypeFontGenerator to set a font and then Update the button:
private void UpdateButton(float xf, float width, float height) {
if (xf > grayButton.getX() + grayButton.getWidth() / 2) {
width += 20;
height += 20;
} else {
width -= 20;
height -= 20;
}
params.size = (int) ((int) width / 4.0);
fontB = generator.generateFont(params);
grayButtonStyle.font = fontB;
grayButton.remove();
grayButton = new TextButton("abcABC", grayButtonStyle);
grayButton.setSize(width, height);
grayButton.setPosition((screenWidth - width) / 2, (screenHeight - height) / 2);
grayButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
UpdateButton(Gdx.input.getX(), grayButton.getWidth(), grayButton.getHeight());
}
});
stage.addActor(grayButton);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.