Search code examples
javacodenameone

Material Image Size relative to Button[codenameone]


I use FontImage.setMaterialImage(...) or sometimes FontImage.createMaterialImage(...).

How can I ensure the material image size increases or its minimum size is 48x48 px.

Lukman Jaji


Solution

  • I suggest not thinking in pixels but thinking in millimeters as this make far more sense with varying screen sizes.

    When you invoke code such as:

    FontImage.setMaterialIcon(label, FontImage.MATERIAL_3D_ROTATION);
    

    The image will get the size of the font assigned to the given label. So if the label is styled with a standard medium font (the default) the size will be system specific. To customize this do:

    label.setUIID("MyFontUIID");
    

    Then in the designer theme:

    1. Add MyFontUIID
    2. Select the Font tab and select any native font.
    3. Select the size to be in millimeters or pixels to determine a fixed size to the icon. I would recommend millimeters for portability.