A simple dialog making it quick and easy to add color picking functionality to any app.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/images
app
colorpickerdialog
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

ColorPickerDialog is a simple dialog making it quick and easy to add a color picker functionality to any app.

Discord

For testing and experimentation purposes, a sample apk can be downloaded here.

Color Picker No Alpha Dark Theme
img img img

Usage

Setup

This project is published on JitPack, which you can add to your project by copying the following to your root build.gradle at the end of "repositories".

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

To add the dependency, copy this line into your app module's build.gradle file.

implementation 'me.jfenn:ColorPickerDialog:0.1.0'

Creating a Dialog

The basic requirements for the dialog are a context, color, and listener, though none of them have to be specified. If you don't specify a listener, though, you can't do anything with the color picked by the dialog, which is not very good.

new ColorPickerDialog(this) // context
  .withColor(color) // the default / initial color
  .withListener(new ColorPickerDialog.OnColorPickedListener() {
    @Override
    public void onColorPicked(ColorPickerDialog dialog, int color) {
      // a color has been picked; use it
    }
  })
  .show();

Alpha

You can also call .withAlpha(boolean) to specify whether you want the colors' alpha to be configurable by the user (if not, all output colors will be fully opaque). This option is enabled by default. A somewhat unnecessary example:

new ColorPickerDialog(this)
  .withAlphaEnabled(false) // disable the alpha
  .withListener(...)
  .show();

Theming

You can theme this dialog the same as any other: by passing a second parameter (a style resource) to its constructor. Full "runtime" theming will come later, but now is not later, so you can't do that yet. Here's an example of a ColorPickerDialog with a basic dark theme, demonstrating all of the options you can specify.

new ColorPickerDialog(this, R.style.ColorPickerTheme).show();
<style name="ColorDialog.Dark" parent="Theme.AppCompat.Dialog">
  <item name="redColor">#FF5252</item>
  <item name="greenColor">#FF5252</item>
  <item name="blueColor">#536DFE</item>
  <item name="neutralColor">#FFFFFF</item>
</style>

The redColor, greenColor, and blueColor attributes affect the RGB sliders, and the neutralColor attribute changes the "neutral" colors of the others, including the alpha slider and the handles of the sliders in the HSL picker.