Creating an Android colour picker dialog

A colour picker lets people set a theme, annotation, label or highlight without leaving the current screen. An Android color picker dialog should offer a live preview, obvious controls and a clear confirmation action while remaining usable on compact phones, tablets and with TalkBack. The result should be predictable, so the host screen can apply the selected colour without extra conversions.

Build the feature as a DialogFragment containing a custom view. A slider-based picker is quicker to implement and easier to operate than a complex gradient wheel, while preset swatches can speed up common choices. Keep network access out of the flow: selecting a colour should work immediately, even when the app is used somewhere with a weak mobile signal.

Choose a focused picker interaction

Start by deciding what the picker is for. If users choose a brand colour for an order, HEX entry and recent swatches are useful. If they adjust a highlight over an image, a large preview matters more than a hex field. A DialogFragment provides dialog lifecycle handling, including recreation after rotation, while AlertDialog supplies familiar buttons and dismissal behaviour.

Three HSV sliders—Hue, Saturation and Value—cover the visible spectrum without demanding precise finger placement. Label the third control Brightness when that is clearer to non-technical users, and show the HEX value beside the preview. If your product already has approved palettes, place those swatches above the sliders. Avoid combining a gradient wheel and sliders unless each has a distinct purpose.

Prepare the colour model and dependencies

Android stores colours as packed ARGB integers, but a picker usually works more naturally in HSV. Hue describes the angle on the colour wheel, while Saturation and Value control intensity and lightness. Convert only when returning the final selection, because maintaining one representation avoids rounding differences. Preserve alpha separately if transparency is genuinely required, and decide whether the interface supports it before adding another control.

Use the AndroidX Fragment and AppCompat libraries already supported by the project. Two small conversion helpers keep the display consistent:

fun hsvToArgb(hue: Float, saturation: Float, value: Float): Int =
    Color.HSVToColor(floatArrayOf(hue, saturation, value))

fun argbToHex(colour: Int): String =
    String.format(Locale.US, "#%06X", 0xFFFFFF and colour)

Always use Locale.US when formatting hexadecimal values so the output contains the expected A to F digits. Technical Android identifiers can remain Color, while visible Australian labels should use “colour”. If users can type a HEX value directly, accept the common three- and six-digit forms and reject incomplete or malformed input without closing the dialog.

Build the picker layout

Create dialog_colour_picker.xml with a vertical LinearLayout: a preview at the top, labelled sliders, an optional hex readout and preset swatches if required. Give the preview a stable height so moving a slider does not shift the controls. Use wrap_content for labels, match_parent for the preview and at least 48dp touch targets for swatches.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="24dp">

    <View
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="96dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hue" />

    <SeekBar android:id="@+id/hue"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="359" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Saturation" />

    <SeekBar android:id="@+id/saturation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="100" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Brightness" />

    <SeekBar android:id="@+id/value"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="100" />

    <TextView android:id="@+id/hex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

Handle light and dark themes by allowing the preview’s surrounding surface to inherit from the app theme. Give the preview and each slider a meaningful accessibility label, and make sure the selected colour is not communicated through colour alone. A visible HEX value or “Selected” message helps users who cannot distinguish the chosen shade.

Connect the controls and return the selection

Wire each slider to a render function that converts HSV to an ARGB integer, updates the preview and formats the hex readout. Return the value with FragmentResult so the host does not depend on the dialog’s internal views.

class ColourPickerDialogFragment : DialogFragment() {
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val view = requireActivity().layoutInflater.inflate(
            R.layout.dialog_colour_picker, null
        )

        val preview = view.findViewById<View>(R.id.preview)
        val hex = view.findViewById<TextView>(R.id.hex)
        val hue = view.findViewById<SeekBar>(R.id.hue)
        val saturation = view.findViewById<SeekBar>(R.id.saturation)
        val value = view.findViewById<SeekBar>(R.id.value)
        var selected = Color.RED

        hue.contentDescription = "Hue"
        saturation.contentDescription = "Saturation"
        value.contentDescription = "Brightness"
        preview.contentDescription = "Colour preview"

        fun render() {
            selected = hsvToArgb(
                hue.progress.toFloat(),
                saturation.progress / 100f,
                value.progress / 100f
            )
            preview.setBackgroundColor(selected)
            hex.text = argbToHex(selected)
        }

        listOf(hue, saturation, value).forEach { bar ->
            bar.setOnSeekBarChangeListener(object :
                SeekBar.OnSeekBarChangeListener {
                override fun onProgressChanged(s: SeekBar, p: Int, u: Boolean) =
                    render()

                override fun onStartTrackingTouch(s: SeekBar) = Unit
                override fun onStopTrackingTouch(s: SeekBar) = Unit
            })
        }

        render()

        return AlertDialog.Builder(requireContext())
            .setTitle("Choose a colour")
            .setView(view)
            .setNegativeButton("Cancel", null)
            .setPositiveButton("Use colour") { _, _ ->
                parentFragmentManager.setFragmentResult(
                    "colour_picker",
                    bundleOf("colour" to selected)
                )
            }
            .create()
    }
}

The FragmentResult bundle keeps the host screen decoupled from the dialog implementation. Register its listener before showing the fragment, then apply the returned integer to the relevant theme, image overlay or drawing tool. For production use, accept an initial colour through fragment arguments and save the current selection in savedInstanceState or a ViewModel.

If the colour will be used behind text, calculate the contrast against white and black rather than choosing an arbitrary fallback. Validate editable hex fields as the user types, but do not update the preview until the complete value can be parsed. Apply the chosen colour to a real sample object before confirmation so users can judge the result in context.

Test the experience for Australian users

Australian English uses “colour” and “customise”, while Android resource and API names continue to use the American spelling. Keep interface copy friendly and direct: “Use colour” is more approachable than “Commit Selected RGB Value”. Check the full flow with Australian English resources instead of relying on the default device language.

Consider how the dialog behaves in local conditions. Someone using the app on a Melbourne or Sydney train may need one-handed controls, while bright daylight near Bondi or Darwin can make subtle colour differences harder to see. Regional users around Kalgoorlie or Alice Springs may also have intermittent mobile coverage, which is why the picker should remain entirely offline.

Australia’s Android audience includes flagship Samsung and Google devices as well as lower-cost handsets with older Android versions and smaller screens. Test keyboard navigation, TalkBack, rotation, dark mode and the oldest supported release. On Google Play, Australian purchases are presented in AUD with applicable GST included; paid colour packs can use a staged rollout while crash reports and device coverage are checked.


Start with the slider-based dialog, then apply the returned ARGB value to a live sample in the host screen. Test it on a budget handset and the oldest supported Android release before shipping through a staged Google Play rollout.

Build the colour picker into the next Android release, keep it responsive and offline, and give users an immediate visual result they can trust.