Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rainbow colour picker android

I want to create a rainbow colour picker which has all the shades as shown in the screenshot. I searched a lot, but didn't get anything that would help me. I got a demo where I can give Array of colour codes to picker. But as there are many shades I don't think this is the best approach. enter image description here

like image 342
madhuri H R Avatar asked Nov 18 '25 12:11

madhuri H R


1 Answers

Use this code:

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;
import  android.support.v4.graphics.ColorUtils;


public class MainActivity extends AppCompatActivity {

ImageView im;
float[] hsl = {0f,.65f,0.5f};//Position 0 = hue , 1 saturation, 2= lightness
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SeekBar sb = findViewById(R.id.seekBar);
    //design your custom seek bar to make look like that
    im = findViewById(R.id.imageView);
    sb.setMax(360);



    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            hsl[0] = progress;
            int color = ColorUtils.HSLToColor(hsl);
            im.setBackgroundColor(color);


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });



}
}
like image 76
Sayok Majumder Avatar answered Nov 20 '25 02:11

Sayok Majumder