DialogFragment UI with Positive / Negative Button

I have a custom DialogFragment (support library). I set the layout as @ color / GhostWhite, the problem is that I cannot find a way to set the positive / negative button in the same color.

This is how I set the buttons:

        builder.setView(view)
    // Add action buttons
           .setPositiveButton("Shout!", new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int id) {
                   //publishStory(/*shoutText.getText().toString()"woww");
                   mListener.onDialogPositiveClick(WagDialogFragment.this);
               }
           })
           .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
               }
           });  

    return builder.create();
0
source share
2 answers

you can call getButtonwith the parameters DialogInterface.BUTTON_POSITIVEand DialogInterface.BUTTON_NEGATIVEto change the color of both buttons as:

Button okButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
// set OK button color here
okButton.setBackgroundColor(R.color.GhostWhite);

Button noButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
// set NO button color here
noButton.setBackgroundColor(R.color.GhostWhite);
+5
source

After calling create, you can call getButton in the returned AlertDialog and set the color on this button.

+1
source

Source: https://habr.com/ru/post/1548023/


All Articles