大家好! 我正在尝试使用 libgdx 和 scene2d 设置 TextButton 中文本的大小。
以下是我创建和初始化文本按钮对象的方法:
Skin skin = new Skin();
skin.add("white", new Texture(Gdx.files.internal("data/texture.jpg")));
skin.add("default", new BitmapFont());
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white");
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);
TextButton newGame = new TextButton("Hello button",skin);
之后,带有文本的按钮就完美创建了,但我不明白如何更改它的文本大小。
我已经尝试了 Label 对象的几乎所有方法:
newGame.getLabel().setScale(10);
newGame.getLabel().setWidth(100);
等等。所以我的问题是:如何更改 TextButton 中的文本大小?
最佳答案
尝试将字体比例设置为按钮的标签。
tb.getLabel().setFontScale(5.0f);
关于android - 调整文本按钮中的文本大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17785463/