@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.color_selector); view = (LinearLayout) findViewById(R.id.contentSelector); backView = (RelativeLayout) findViewById(R.id.rootSelector); backView.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getX() < view.getLeft() || event.getX() > view.getRight() || event.getY() > view.getBottom() || event.getY() < view.getTop()) { dismiss(); } return false; } }); colorView = findViewById(R.id.viewColor); colorView.setBackgroundColor(color); // Resize ColorView colorView.post( new Runnable() { @Override public void run() { LayoutParams params = (LayoutParams) colorView.getLayoutParams(); params.height = colorView.getWidth(); colorView.setLayoutParams(params); } }); // Configure Sliders red = (Slider) findViewById(R.id.red); green = (Slider) findViewById(R.id.green); blue = (Slider) findViewById(R.id.blue); int r = (this.color >> 16) & 0xFF; int g = (this.color >> 8) & 0xFF; int b = (this.color >> 0) & 0xFF; red.setValue(r); green.setValue(g); blue.setValue(b); red.setOnValueChangedListener(this); green.setOnValueChangedListener(this); blue.setOnValueChangedListener(this); }
@Override public void onValueChanged(int value) { color = Color.rgb(red.getValue(), green.getValue(), blue.getValue()); colorView.setBackgroundColor(color); }