Home > Software design >  My app crashes when add custom colors in ColorPicker library?
My app crashes when add custom colors in ColorPicker library?

Time:08-15

Here is the code that I have problem with. The problem occurs when I add hex colors to it. Otherwise with default colors works fine.

public void openColorPicker(){

    ColorPicker colorPicker = new ColorPicker(this);

    ArrayList<String> colors = new ArrayList<>();
    colors.add("#122000");
    colors.add("#ab234");
    colors.add("#cf2387");
    colors.add("#003399");
    colors.add("#fb3498");
    colors.add("#5123fff");
    colors.add("#12a1bf");

    colorPicker.setColumns(4);
    colorPicker.setColors(colors);
    colorPicker.setOnFastChooseColorListener(new ColorPicker.OnFastChooseColorListener() {
        @Override
        public void setOnFastChooseColorListener(int position, int color) {
            etNote.setBackgroundColor(color);
            toolbar.setBackgroundColor(color);
        }

        @Override
        public void onCancel() {

        }
    }).show();
}

My second question is how to add another color for to the title bar, I want a color variant to it, a lighter color.

CodePudding user response:

The library seems to use Color.parseColor() for decoding the hex strings passed in. The supported color formats are #RRGGBB and #AARRGGBB. Your list has two values that don't follow there patterns with five or seven hex digits instead of six or eight.

  • Related