Home > Net >  Can't get Github Colorpicker to work for Android using Kotlin
Can't get Github Colorpicker to work for Android using Kotlin

Time:12-28

I want to use a colorpicker for my android application. I tried to get it working by following the steps on github. I can open the Dialog but don't really understand how to return a color. Here is the Github dependencie I'd like to use: https://github.com/skydoves/ColorPickerView. Edit: I want to use it as a dialog that I open over a button that calls this function.

private fun openColorPickerDialog(): String {

    val builder = ColorPickerDialog.Builder(this)
    builder.setTitle("Choose custom color!")
    builder.setPreferenceName("MyColorPickerDialog")
    builder.setPositiveButton(getString(R.string.confirm), ColorEnvelopeListener { envelope, fromUser -> })
    builder.setNegativeButton(getString(R.string.cancel), DialogInterface.OnClickListener { dialogInterface, i -> dialogInterface.dismiss() })
    builder.show()

    return
}

Here's what I have so far. It opens the dialog and now I want to return if possible a Hex-Color string what I then can use.

CodePudding user response:

Use this to get your color picked in Hex

builder.setColorListener(new ColorEnvelopeListener() {
@Override
public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {
    textView.setText("#"   envelope.getHexCode());
   }
});
  • Related