gluonmobile has font bug on android os

随声附和 提交于 2019-12-02 08:19:06

By default Gluon Mobile uses Roboto font, which doesn't include Chinese characters.

One easy way you can solve this issue is by setting any of the Android system fonts that do include them.

Using Font.getFamilies() on my Android device I discovered this one: Noto Sans CJK SC Regular. Probably you will have that too, or if not, another similar family.

So you can easily create a css file (src/main/resources/style.css) with this content:

.view {
    -fx-font-family: "Noto Sans CJK SC Regular";
}

and then load it in your view:

public BasicView(String name) {
    super(name);

    getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
    ...
}

That should work.

EDIT

In order to apply the font to the AppBar as well, the css has to be set to the Scene, as this control is not part of the view.

In the MobileApplication class:

@Override
public void postInit(Scene scene) {
    Swatch.BLUE.assignTo(scene);
    scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
}

Then you'll need to apply the font to the root, and all the different controls that make use of a different font, like the AppBar:

.root,
.app-bar > .title-box > .label {
    -fx-font-family: "Noto Sans CJK SC Regular";
}

Note that you can use ScenicView to find out about the style classes for those controls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!