Dialog box disappears during orientation change in fragment

穿精又带淫゛_ 提交于 2019-11-29 16:14:50
Ronak Mehta

Up to API 13 there was a new value to the configChanges attribute, screenSize

So if you're using large screens make sure to add screenSize in your configChanges attribute:

android:configChanges="orientation|keyboardHidden|screenSize"

i.e.

<activity
    android:name=".MyMainActivity"
    android:configChanges="orientation|keyboardHidden|screenSize" 
    android:label="@string/app_name" >

Reference

Yoric

Try to use DialogFragment instead. It restarts after orientation change. You need to extend this class as shown on documentation, and use it to show dialog.

By accident i found a way to make your Dialog persist when device orientation changes.

This is C# xamarin code but i believe it can be very easily adapted to java as well.

    private void MakeDialogPersist(Dialog dialog)
    {
        WindowManagerLayoutParams wmlp = new WindowManagerLayoutParams();
        wmlp.CopyFrom(dialog.Window.Attributes);
        dialog.Window.Attributes = wmlp;
    }

I run this method after i perform dialog.Show();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!