Search code examples
javaandroidpreference

Android add image to preference?


How can I add an icon to a preference, the preference references an app so I can get the app's icon. I can get the icon as a drawable from the app, how can I add it to the preference?

        Preference preference = new Preference(this);
        preference.setTitle(app.activityInfo.loadLabel(pm));

EDIT:

I used this, but it says it requires at least api lvl 11, I hope someone comes with a better solution though:

        if(sdk > android.os.Build.VERSION_CODES.HONEYCOMB) {
            preference.setIcon(app.loadIcon(pm));
            }

Solution

  • I'm doing this which only works on android post honeycomb, I hope there is a more compatible option:

            if(sdk > android.os.Build.VERSION_CODES.HONEYCOMB) {
                preference.setIcon(app.loadIcon(pm));
                }