Why App crashes when applying color to edittext text in android?

157 views Asked by At
private void ShowPicker() {
    AlertDialog colorPickerDialog= new ColorPickerDialog.Builder(getContext())
            .setTitle("ColorPicker Dialog")
            .setPreferenceName("MyColorPickerDialog")
            .setPositiveButton("Confirm",
                    new ColorEnvelopeListener() {
                        @Override
                        public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {
                            textEditBottomSheetCallback.SetTextColor(envelope.getColor());
                        }
                    })
            .setNegativeButton("cancel",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                        }
                    })
            .attachAlphaSlideBar(true) // the default value is true.
            .attachBrightnessSlideBar(true)  // the default value is true.
            .setBottomSpace(12) // set a bottom space between the last slidebar and buttons.
            .show();
    colorPickerDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.blue));
    colorPickerDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.blue));
}
@Override
public void SetTextColor(int color) {
    edtTitle.setTextColor(ContextCompat.getColor(getContext(),color));
    edtText.setTextColor(ContextCompat.getColor(getContext(),color));
}

In show picker method I am using skydove color picker library and in set text color method I set color to edittext text. App crashes when I select color from color picker dialog. Any suggestions about this problem. Sky Dove Library

1

There are 1 answers

0
Aravind Varma On

No log provided but my guess is that you are applying color to the dialog after it is being shown. Try this:

private void ShowPicker() {
AlertDialog colorPickerDialog= new ColorPickerDialog.Builder(getContext())
        .setTitle("ColorPicker Dialog")
        .setPreferenceName("MyColorPickerDialog")
        .setPositiveButton("Confirm",
                new ColorEnvelopeListener() {
                    @Override
                    public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {
                        textEditBottomSheetCallback.SetTextColor(envelope.getColor());
                    }
                })
        .setNegativeButton("cancel",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                })
        .attachAlphaSlideBar(true) // the default value is true.
        .attachBrightnessSlideBar(true)  // the default value is true.
        .setBottomSpace(12); // set a bottom space between the last slidebar and buttons.
        
colorPickerDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.blue));
colorPickerDialog.show();
}