简体   繁体   中英

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));
            }

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));
            }

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