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..

It is significant when you lose this market. And absolutely not significant when users just don't see additional icons.
–
VadimOct 20 '14 at 11:03

Anyone know what happens if you run it in 2.3? Does it cause an issue or just the icon doesn't show? If it silently just doesn't show the icon w/o distorting the layout then I feel its acceptable to not have that that feature for 5-10%, icons & bitmaps take up memory on lower end devices running 2.3 anyways..
–
AlexVPerlDec 22 '14 at 6:08

This doesn't work for me. No icon appears and when I next preferences within, the app crashes. Do you know of a way to have and Icon on the label of a PreferenceScreen?
–
Camille SévignyAug 29 '11 at 18:40

This solution worked for me. I don't understand why you have to set the icon in the preference activity when the IconPreferenceScreen takes the time to pull it out of attrs, but you do.
–
ChiatarFeb 17 '12 at 19:20

3

The example you've posted isnot a PreferenceScreen in any way shape or form. You've basically just added an image to the layout of a generic preference that won't actually do anything when selected.
–
Justin BuserMar 27 '12 at 10:55

I know that this image isn't a PreferenceActivity, but I know it's posible to add an icon to Preference using the IconPreferenceScreen class like in the Settings android App.. I cloned the IconPrefScreen class and the preference_icon XML, and I added the IconPrefScreen attribute to attrs.xml, but at this point I don't know how to create a new IconPreference in my activity.. Please help me if you know how to do it! Thanks
–
Tony CeralvaApr 23 '11 at 19:49

@Tony_GPR: Do you even know what IconPreferenceScreen does?
–
CommonsWareApr 23 '11 at 20:13

extends the Preference class, with the option to add an icon. Am I wrong?
–
Tony CeralvaApr 24 '11 at 1:19

@Tony_GPR: You are wrong. PreferenceScreen, as you may recall, serves two roles: it is the root XML element, and it also serves as the starting point for a nested screen of preferences. In that second role, the PreferenceScreen's title and description serve as what the user taps on from the original screen of preferences to get to the nested screen of preferences. IconPreferenceScreen is simply a PreferenceScreen with an icon on the side. It has no impact whatsoever on any other preferences.
–
CommonsWareApr 24 '11 at 11:32

1

@Tony_GPR: This is why I said that "it will be simpler for you to just create your own activity that happens to save preferences." You will have to subclass each and every type of Preference you want to use and rewire it to have an icon next to it. Again, I REALLY ENCOURAGE YOU TO NOT DO THIS. Android developers have a reputation of being morons when it comes to UI standardization, because Android developers do things like add icons where they don't belong. Users and media members complain that no two Android apps look and work the same, unlike with iOS. Please leave the preferences alone.
–
CommonsWareApr 24 '11 at 11:35