Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add icons to Preference

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); 
like image 700
Tony Ceralva Avatar asked Apr 23 '11 15:04

Tony Ceralva


People also ask

How do I set custom preferences on Android?

It's still possible to customise the appearance of a Preference item though. In your XML you have to declare the root element as android:id="@android:id/widget_frame , and then declare TextView as android:title and android:summary . You can then declare other elements you want to appear in the layout.


1 Answers

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

like image 61
Vadim Avatar answered Sep 30 '22 09:09

Vadim