我想为工具栏中的命令使用 Material FontImage。那行得通,但我不知道如何更改图像的大小。我找不到用 Style 做到这一点的方法,因为它没有样式选项。 我发现我可以用这个改变字体大小:
style.setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
FontImage.createMaterial(FontImage.MATERIAL_SETTINGS, style);
但是如何将其更改为例如像素?
最佳答案
大小由主题中的Style决定。
虽然您也可以使用 derive 更改高度:
style.setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE).derive(fontHeight, Font.STYLE_PLAIN));
FontImage.createMaterial(FontImage.MATERIAL_SETTINGS, style);
您可以使用以下方法设置像素大小:
FontImage icon = FontImage.createFixed("" + FontImage.MATERIAL_SETTINGS, FontImage.getMaterialDesignFont(), colorRGB, widthPixels, heightPixels);
但最好的设置方式是使用:
FontImage.setMaterialIcon(myComponent, FontImage.MATERIAL_SETTINGS);
这是最好的方法,因为图标将从您的组件派生样式(字体大小、前景色等),这意味着您不需要为此做任何事情,并且您的随意样式自定义将隐式应用。
关于java - Codename One createMaterial 命令的图标大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35044971/