0

I'm working on an Android App. I have the need to customize Alert Dialog buttons because it shows me the buttons in an unspecified way.

enter image description here

The code to invoke the alert dialogue is:

 new AlertDialog.Builder(context,R.style.dialog_theme)
                .setTitle(R.string.dialog_title_avviso)
                .setMessage(messageResId)
                .setPositiveButton(R.string.dialog_button_si, (dialog, which) -> listener.onResponse(dialog, DialogResponse.OK))
                .setNegativeButton(R.string.dialog_button_no, (dialog, which) -> listener.onResponse(dialog, DialogResponse.CANCEL))
                .show();

In the style.xml I define the following style:

<style name="dialog_theme" parent="Theme.AppCompat.Light.Dialog.Alert">
  <item name="android:windowTitleStyle">@style/AlertDialogTitleStyle</item>
</style>

I would like to set the dialogue in the following mode:

enter image description here

Any ideas? Thanks

xcesco
  • 4,690
  • 4
  • 34
  • 65

1 Answers1

0

create alert dialog object first, and then use it to change color of text inside button.

CustomDialog builder = new CustomDialog(getActivity(), "Try Again", errorMessage); 
    AlertDialog dialog = builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        ...
                    }

                }).create();


    dialog.setOnShowListener( new OnShowListener() {
        @Override
        public void onShow(DialogInterface arg0) {
            dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(COLOR.BLUE);
        }
    });

    dialog.show()