简体   繁体   中英

How to set the application icon for a libGDX desktop application?

I am trying to setup an application icon from the -desktop specific class with:

package org.osgameseed.games.animalflip;

import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

public class Main {
    public static void main(String[] args) {
        LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
        cfg.title = "AnimalFlip";
        cfg.useGL20 = false;
        cfg.width = 800;
        cfg.height = 600;
        cfg.addIcon("data/ic_launcher.png", Files.FileType.Internal);

        new LwjglApplication(new AnimalFlipGame(), cfg);
    }
}

The icon is not set (at least on Linux), any idea on how to set it ?

Take a look into the api (addIcon(...)):

. Icons are tried in the order added, the first one that works is used. Typically three icons should be provided: 128x128 (for Mac), 32x32 (for Windows and Linux), and 16x16 (for Windows).

Maybe your icon has the wrong dimensions, so it won't get set. Else it should work!


小图标

that brought the Icon into my Mac-Dock! ;) Be sure to call it in your Lwjgl-Thread

/**
 * workaround for Mac
 */
private static void setApplicationIcon() {
    try {
        Class<?> cls = Class.forName("com.apple.eawt.Application");
        Object application = cls.newInstance().getClass().getMethod("getApplication").invoke(null);

        FileHandle icon = Gdx.files.local("icons/icon.png");
        application.getClass().getMethod("setDockIconImage", java.awt.Image.class)
                .invoke(application, new ImageIcon(icon.file().getAbsolutePath()).getImage());
    } catch (Exception e) {
        // nobody cares!
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM