How to create a ColorDialogPreference
The standard set of preferences does not provide a Color wheel·preference. This article describes how you can create a color picker preference. We do this by making use of a DialogPreference with a custom layout and the color picker example provided by Android. The layout is done with custom coding. A sample application is provided to show the working.
The result wil be either one of the screenshots below depending on the color scheme used.


The example provided by Android contains some functionality which is not feasible for a Preference. To make your color choice final, you had to select the inner circle for instance. This functionality is removed. We just use the inner circle to display the selected color in the outer circle. We start with deriving our ColorDialogPreference from the Android DialogPreference class (instead of Dialog). To make·it possible to persist the selected color, we override the onDialogClosed and onPrepareDialogBuilder methods. In the onDialogClosed method we store the selected color (if needed) and in the onPrepareDialogBuilder we are creating the ColorChangeListener and the View. This is exactly the same as within the onCreate of the original Android example. Additionally, we retrieve the previous selected color). And thats it. Have fun!
The ColorDialogPreference is used within the following apps:
- Battery Widget
-·Hearts Live Wallpaper
-·Rose Petals·Live Wallpaper
-·Spyro·Live Wallpaper
-·Stars Live Wallpaper
- Star Trek Clock Widget
-·Tweet Live Wallpaper
-·Tweet Widget