0

I want to hide buttons from my AlertDialog. I found this solution but it simply disables the buttons.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    ...
    AlertDialog dialog = builder.create();
    Button button = dialog.getButton(Dialog.BUTTON_POSITIVE);
    button.setEnabled(false);

    return dialog;
}
user1506104
  • 6,554
  • 4
  • 71
  • 89

1 Answers1

0

You have to set the button's visibility to GONE instead of using setEnabled(). Also, you have to do this in the onStart() of your dialog like so:

@Override
public void onStart() {
    super.onStart();

    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        Button negativeButton = d.getButton(Dialog.BUTTON_NEGATIVE);
        positiveButton.setVisibility(View.GONE);
        negativeButton.setVisibility(View.GONE);
    }
}
user1506104
  • 6,554
  • 4
  • 71
  • 89