Links

GitHub Issues Apache License 2.0 JitPack ColorPickerDialog.apk (0.1.0 stable)

Contributors

fennifith jahirfiquitiva

Color Picker Dialog

git://github.com/fennifith/ColorPickerDialog.git

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

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.

Last updated: 2018-11-08 16:40:29 +0000

This site may do shady things with cookies and stuff because it's evil. Please don't read my privacy policy. close