分享一个android颜色选择器的使用教程

先付上原作者git地址

https://github.com/AzeeSoft/AndroidPhotoshopColorPicker


怎么说呢。。超简单!超小!超好用。

分享一个android颜色选择器的使用教程


就几个类文件。

demo写的东西有点多。

其实你只要从git下载library

然后把build的

apply from: rootProject.file('gradle/maven-push.gradle')
给注释了就可以了
要用到的地方因用一下library

食用方法 超简单

如果你实在activity中想选择颜色

你的activity要实现ColorPickerDialogListener接口

例如 
public class MainActivity extends AppCompatActivity implements ColorPickerDialogListener

实现2个方法

@Override
public void onColorSelected(int dialogId, int color) {
    switch (dialogId) {
        case DIALOG_ID:
            //返回的颜色 color
            break;
    }
}

@Override
public void onDialogDismissed(int dialogId) {

}


然后再就如下


ColorPickerDialog.newBuilder()
	//类型
        .setDialogType(ColorPickerDialog.TYPE_CUSTOM)
        .setAllowPresets(false)
	//窗口Id
        .setDialogId(DIALOG_ID)
	//初始颜色
        .setColor(Color.BLACK)
        .setShowAlphaSlider(true)
        .show(this);

然后就弹出对话框了


简单明了 


如果是Fragment的话 想使用这个控件 需要改动下。
  当然 实现那部分是一样的
不一样的就是创建部分


ColorPickerDialog dialog = ColorPickerDialog.newBuilder()
        .setDialogType(ColorPickerDialog.TYPE_CUSTOM)
        .setAllowPresets(false)
        .setDialogId(START_COLOR_ID)
        .setColor(p.getStartColor())
        .setShowAlphaSlider(true)
        .create();

dialog.setColorPickerDialogListener(当前类名.this);
dialog.show(getActivity().getFragmentManager(), "color");

后面这个"color"是一个tag  区分用的。

就酱。

真的超简单超好用。。。


附上 library地址

http://download.****.net/detail/zx4471/9845658