Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using icons in Android preferences

I would like some of my preferences to have icons, like the Settings app.

I guess one way of doing this would be to copy all the relevant code and resources from the Settings app, but it seems like overkill for a couple of icons.

Also I don't like the idea of having to duplicate the code and resources in each project that requires settings icons.

Has anyone solved this already with a simpler or resource-free approach?

like image 275
hpique Avatar asked Apr 15 '10 14:04

hpique


People also ask

How do I make my Android icons adaptive?

Add your adaptive icon to your app xml , create alternative drawable resources in your app for backward-compatibility with Android 8.0 (API level 26). You can then use the <adaptive-icon> element to define the foreground, background, and monochromatic layer drawables for your icons.

What is launcher icon in Android?

A Launcher icon is a graphic that represents your application on the device's Home screen and in the Launcher window. The user opens the Launcher by touching the icon at the bottom of the Home screen. The Launcher opens and exposes the icons for all of the installed applications.


1 Answers

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.

source code

like image 137
CommonsWare Avatar answered Oct 04 '22 19:10

CommonsWare