简体   繁体   中英

How to change/update the custom layout of a Dialog on orientation change in android

Im trying to change the layout of a Dialog in the onConfigurationChange of the activity. I have created 2 layout one in regular layouts folder and other in layouts-land, i can get the layouts if the orientations of the device is in landscape or portrait and then click to show the dialog. But if I try to change the orientation when the dialog is showing the custom layout in using is not updating.

Please help me out with this. I don't wanna use a DialogFragment to do this, is there a easier way to fix it by just using regular AlertDialog.

Thanks.

You should create two different layouts, one for portrait and another for landscape. Then call for layout on orientation change. Search for alert dialog with own layouts.

LayoutInflater inflater = getLayoutInflater();
View alertLayout = inflater.inflate(R.layout.layout_custom_dialog,null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Info");
alert.setView(alertLayout);
AlertDialog dialog = alert.create();
dialog.show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM