Dialog box disappears during orientation change in fragment

后端 未结 3 1016
余生分开走
余生分开走 2020-12-21 06:15

So I am not a very experience Android programmer, so please be gentle with me :)

I am trying to create an app that uses fragements and from within one of these fragm

相关标签:
3条回答
  • 2020-12-21 06:59

    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

    0 讨论(0)
  • 2020-12-21 07:13

    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();

    0 讨论(0)
  • 2020-12-21 07:14

    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.

    0 讨论(0)
提交回复
热议问题