Android AlertDialog Default Orientation

I would like to change the default setting for the Alert dialog for Landscape by default. I do not want to handle the orientation of the dialog when changing the orientation of the device.

AlertDialog.Builder builder = new AlertDialog.Builder(MenuActivity.this); builder.setMessage("Are you sure you want to exit?") .setCancelable(false) .setTitle("EXIT") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MenuActivity.this.finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.setIcon(R.drawable.ic_launcher); alert.show(); 

I cannot find what specifically handles the default orientation of this dialog? Any help would be greatly appreciated. Thanks in advance.

+4
source share
2 answers

You can use this method in your work.

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

+1
source

I have not tested, but maybe this will work for you.

You need to implement a custom AlertDialogStyle and embed it in your code. See Here: for creating a user dialog

And in the style file add properties like

 <item name="android:orientation">landscape</item> 

Hope this works for you.

Enjoy the coding. ,,.

0
source

All Articles