Skip to content

SimpleColorDialog

Eltos edited this page Oct 29, 2021 · 5 revisions

Color palette picker

extends CustomListDialog

API reference Examples

A dialog that can be used to choose a color from a pallet. It also allows to pick a custom color using the SimpleColorWheelDialog.

Usage

For general usage see SimpleDialog and CustomListDialog.

Additional methods are provided to specify the color pallet (colors), the initial color (colorPreset), whether a field for custom colors is shown (allowCustom), the selection mode (choiceMode, see CustomListDialog), the color field style (showOutline) etc. Please refer to the API reference for a comprehensive documentation of these methods.

The dialog provides a number of predefined color palettes:

SimpleColorDialog.MATERIAL_COLOR_PALLET SimpleColorDialog.MATERIAL_COLOR_PALLET_LIGHT SimpleColorDialog.MATERIAL_COLOR_PALLET_DARK SimpleColorDialog.BEIGE_COLOR_PALLET SimpleColorDialog.COLORFUL_COLOR_PALLET

Receiving results

For general usage see SimpleDialog and CustomListDialog.

The extras Bundle returned will contain the following additional keys:

@ColorInt int color = extras.getInt(SimpleColorDialog.COLOR);  // The color chosen 
int[] colors = extras.getIntArray(SimpleColorDialog.COLORS);   // Colors chosen if multi select was enabled

Examples

SimpleColorDialog.build()
                 .title(R.string.pick_a_color)
                 .allowCustom(true)
                 .colorPreset(0xff009688)
                 .show(this, DIALOG_TAG);
SimpleColorDialog.build()
                 .title(R.string.pick_a_color)
                 .choiceMode(CustomListDialog.MULTI_CHOICE)
                 .colors(this, SimpleColorDialog.COLORFUL_COLOR_PALLET)
                 .choiceIdPreset(new long[]{0xfffff78c, 0xff00ff61, 0xff1d7fb9})
                 .choiceMin(2).choiceMax(5)
                 .allowCustom(true)
                 .showOutline(SimpleColorDialog.AUTO)
                 .show(this, DIALOG_TAG);