How to add icons to Preference

Tony Ceralva picture Tony Ceralva · Apr 23, 2011 · Viewed 34.4k times · Source

I'm making an app that extends the PreferenceActivity and I want to add an icon to each Preference.

I read a similar question, and this is the answer with more reputation:

CommonsWare Say:

The Settings application uses a private custom PreferenceScreen subclass to have the icon -- IconPreferenceScreen. It is 51 lines of code, including the comments, though it also requires some custom attributes. The simplest option is to clone all of that into your project, even though you do not like that.

But I can't make it work. For now I cloned the class IconPreferenceScreen to my project. And I don't know what I have to do after this. I'm trying to make a new IconPreferenceScreen I can't make it work..

    IconPreferenceScreen test = new IconPreferenceScreen();
    test.setIcon(icon);

Answer

Vadim picture Vadim · May 28, 2013

Today you can just use android:icon attr available since API 11 :)