Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

itsaky/MaterialColorPicker

Repository files navigation

MaterialColorPicker

license

MaterialColorPicker made for Android. Written in Java with AIDE

Download

Add it in your root build.gradle at the end of repositories:

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

Add the dependency

dependencies {
    implementation 'com.github.itsaky:MaterialColorPicker:<lastest-version>'
}

Usage

  • 1. Create a ColorPickerDialog instance using one of the following methods :

    • a.
    // Alpha slider will be invisible
    ColorPickerDialog view = new ColorPickerDialog(this);
    • b.
    // Alpha slider will be visible
    ColorPickerDialog view = new ColorPickerDialog(this, "#f44336");
    • c.
    //Alpha slider will be visible
    ColorPickerDialog view = new ColorPickerDialog(this, /*alpha*/255, /*red*/ 255, /*green*/ 255, /*blue*/ 255);
    • d.
    // Alpha slider will be invisible
    ColorPickerDialog view = new ColorPickerDialog(this, /*red*/ 255, /*green*/ 255, /*blue*/ 255);
  • 2. Modify values

    // Setters
    view.setAlpha(255);
    view.setRed(255);
    view.setGreen(255);
    view.setBlue(255);
    view.withAlpha(true); // enables alpha slider
    view.setCloseOnPicked(false); // Prevents closing of dialog when 'pick' is clicked
  • 3. Getting values

    view.getAlpha();
    view.getRed();
    view.getGreen();
    view.getBlue();
    view.getColor(); // returns int value of current color
    view.getHexColorCode(); // if withAlpha then with alpha hex value else without it
    view.getHexWithAlpha();
    view.getHexWithoutAlpha();
  • 4. Callback Get callback when 'pick' is clicked

    view.setColorPickerCallback(new ColorPickerDialog.ColorPickerCallback(){
      @Override
      public void onColorPicked(int color, String hexColorCode)
      {
        Toast.makeText(getApplicationContext(), "int[" + color + "] hex[" + hexColorCode + "]", Toast.LENGTH_LONG).show();
      }
    });

License