0

I'm using this code:

@Override
protected void onResume() {
    super.onResume();
    
    AlertDialog d = new AlertDialog.Builder(this)
            .setTitle("This is the Dialog Title")
            .setMessage("This is the Test message")
            .setPositiveButton("Positive Button", (dialog, which) -> {
                dialog.dismiss();
            })
            .create();
    
    rotateDialog(d);
    
    d.show();
}

public static void rotateDialog(Dialog curDlg) {
    Window window = curDlg.getWindow();
    if (window != null) {
        View decorView = window.getDecorView();
        decorView.setRotation(-90);
    }
}

Before rotation, the Dialog looks correctly. But after rotation, it is cropped on Emulator. (DecorView is visualized using LayoutInspector).

Before + after rotation

What code should be used to rotate an AlertDialog correctly?

1
  • 2
    You have not mentioned why you are trying to do that, trying to show alert dialog as if device is in landscape mode? If so you can change the orientation Commented Nov 1 at 12:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.