Search code examples
androidandroid-alertdialogandroid-dialogfragmentcancel-button

Change text of cancel button in Android?


I've created an AlertDialog like so:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

And then I've set the buttons:

return builder.setTitle(titleText).setView(mDialogLayout)
                .setNegativeButton(android.R.string.cancel, null).create();

Is there a way I can change the "NegativeButton" to say something other than "Cancel"?


Solution

  • change this:

    return builder.setTitle(titleText).setView(mDialogLayout)
                    .setNegativeButton(android.R.string.cancel, null).create();
    

    to:

    return builder.setTitle(titleText).setView(mDialogLayout)
                    .setNegativeButton("Text you need", null).create();
    

    setNegativeButton method's first argument can take your text.