1
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Do you want to continue?");
    builder.setMessage("Press Yes or No");
    builder.setCancelable(false);
    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(MainActivity3.this,MainActivity.class);
            startActivity(intent);
        }
    });

Positive button appears on right side instead of the left.

ADM
  • 20,406
  • 11
  • 52
  • 83
Koroski
  • 11
  • 2

1 Answers1

1

By default AlertDialog put the positive button on the right (if you have a Left to right reading setting). AlertDialog is impacted by reading direction settings so it will change based on the layout direction:

getWindows().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

If you want to swap the buttons what is suggested in the comment will work:

  • swap string
  • swap code

It will confuse the user though as they will expect the positive button to be on the right (for LtR readers)

Slamit
  • 465
  • 1
  • 6
  • 21