Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Create a Color Picker Tool in Android using Color Wheel and Slider?

  • Difficulty Level : Basic
  • Last Updated : 22 Oct, 2020

In the previous article How to Create a Basic Color Picker Tool in Android, we have discussed to create a basic color picker tool. In this article, we are going to create the same color picker tool but using a color wheel and slider. This is another type of the Color Picker which allows user to pick the brightness level of the color and color intensity. This is also one of the open-source libraries. So in this article its been discussed to implement the following type of color picker tool.

Color picker tool advanced

A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.

sample GIF

Steps to Implement a Color Picker Tool

Step 1: Create a New Project

Step 2: Adding the ColorPicker library dependency

implementation ‘com.github.duanhong169:colorpicker:1.1.6’

  • Make sure the system should be connected to the network (so that it downloads the required files) and after invoking the dependency click on the “Sync Now” button.
  • Refer to the following image if unable to locate the app-level gradle file and invoke the dependency.

Gradke file

Step 3: Working with the activity_main.xml file

  • Next, go to the activity_main.xml file, which represents the UI of the project.
  • Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.


<?xml version="1.0" encoding="utf-8"?>
    <!--Give all widgets, the proper id to 
        handle them in>
    <!--GeeksforGeeks Text-->
        android:textStyle="bold" />
    <!--Pick color Button-->
        android:text="Pick Color" />
        android:text="Your picked color is:" />
    <!--sample view to preview selected color by user-->
    <!--by default this has been set to darker gery-->
    <!--this can be overridden after user chose the 
        color from color picker-->
    <!--which has been handled in the>
        android:layout_marginTop="8dp" />
    <!--set color button to overwrite the 
        color for GeeksforGeeks text-->
        android:text="Set Color" />

Output UI:

Output UI

Before going to handle the color picker tool dialog functionality, understanding the parts of the dialog box is necessary so that it can become easier while dealing with parts of the dialog box in java code.

Details of dilalog

Step 4: Working with the file

  • Finally, go to the file, and refer to the following code.
  • Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import top.defaults.colorpicker.ColorPickerPopup;
public class MainActivity extends AppCompatActivity {
    // text view variable to set the color for GFG text
    private TextView gfgTextView;
    // two buttons to open color picker dialog and one to
    // set the color for GFG text
    private Button mSetColorButton, mPickColorButton;
    // view box to preview the selected color
    private View mColorPreview;
    // this is the default color of the preview box
    private int mDefaultColor;
    protected void onCreate(Bundle savedInstanceState) {
        // register the GFG text with appropriate ID
        gfgTextView = findViewById(;
        // register two of the buttons with their
        // appropriate IDs
        mPickColorButton = findViewById(;
        mSetColorButton = findViewById(;
        // and also register the view which shows the
        // preview of the color chosen by the user
        mColorPreview = findViewById(;
        // set the default color to 0 as it is black
        mDefaultColor = 0;
        // handling the Pick Color Button to open color
        // picker dialog
                new View.OnClickListener() {
                    public void onClick(final View v) {
                        new ColorPickerPopup.Builder(MainActivity.this).initialColor(
                                Color.RED) // set initial color
                                // of the color
                                // picker dialog
                                        true) // enable color brightness
                                // slider or not
                                        true) // enable color alpha
                                // changer on slider or
                                // not
                                        "Choose") // this is top right
                                // Choose button
                                        "Cancel") // this is top left
                                // Cancel button which
                                // closes the
                                        true) // this is the small box
                                // which shows the chosen
                                // color by user at the
                                // bottom of the cancel
                                // button
                                        true) // this is the value which
                                // shows the selected
                                // color hex code
                                // the above all values can be made
                                // false to disable them on the
                                // color picker dialog.
                                        new ColorPickerPopup.ColorPickerObserver() {
                                            public void
                                            onColorPicked(int color) {
                                                // set the color
                                                // which is returned
                                                // by the color
                                                // picker
                                                mDefaultColor = color;
                                                // now as soon as
                                                // the dialog closes
                                                // set the preview
                                                // box to returned
                                                // color
        // handling the Set Color button to set the selected
        // color for the GFG text.
                new View.OnClickListener() {
                    public void onClick(View v) {
                        // now change the value of the GFG text
                        // as well.

Output: Run on Emulator

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!