android - 调整文本按钮中的文本大小

标签 android libgdx

大家好! 我正在尝试使用 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/

相关文章:

java - 简单的 TextToSpeech 代码

Java HashMap迭代查找驱动结束事件

java - LibGDX Stage vs SpriteBatch 绘制游戏

android - 将 ObjectBox 与 Libgdx 一起使用

java - 如何将文件的行号转换为字节偏移量(或使用 BufferedReader 获取每行开头的字节偏移量)?

android - 我可以调试不是我创建的 .apk 吗

libgdx - 在 libgdx 中玩游戏时如何唤醒屏幕?

java - LibGDX - 调整大小后将粒子渲染在错误的位置

java - LibGdx屏幕: render and lifecycle

android - ListView 中的项目居中 (Android)