旋转屏幕后如何恢复对话框等?例如,弹出一个 alertDialog 告诉用户一些信息.然后用户将屏幕旋转到另一个方向.如何恢复alertDialog?任何人都可以指导我这样做吗?谢谢!
How to restore the dialog etc after rotating the screen? For example, pop up an alertDialog to tell user some information. then the user rotate the screen to another orientation. How to restore the alertDialog? Can any one guide me to do it? Thanks!
稍后添加:
我查看了android源代码并找到了这些东西:
I looked into the android source code and find these things:
对话框存储在mManagedDialogs
中,相关信息为:
Dialogs are stored in mManagedDialogs
, and the related information is:
mManagedDialogs = new SparseArray<ManagedDialog>();
onSaveInstanceState
相关:
final void performSaveInstanceState(Bundle outState) {
onSaveInstanceState(outState);
saveManagedDialogs(outState);
}
在saveManagedDialogs
中,与mManagedDialogs
有关.
onRestoreInstanceState
相关:
final void performRestoreInstanceState(Bundle savedInstanceState) {
onRestoreInstanceState(savedInstanceState);
restoreManagedDialogs(savedInstanceState);
}
在restoreManagedDialogs
中,与mManagedDialogs
有关.
如您所见,对于高级功能,您必须自己完成保存和恢复工作.当您拥有大量自定义对话框时,这可能是一场噩梦.我没有尝试过复杂的对话框(例如输入了 EdiText、listView).通过这种方式,我想警告用户:在对话框中输入信息时切勿旋转屏幕......或者,在显示对话框时动态锁定旋转.
As you can see, for advanced feature, you must do the saving and restoring job by yourself. It may be a night mare when you have tons customized dialogs. I have not tried the complex dialog (has input EdiText, listView, say). In this way, I'd like to warn users: Never rotate the screen when inputing your info in the dialog... OR, lock the rotation dynamically when showing the dialog.
感谢所有回答我的人.希望我的信息也能帮到你.
Thanks for all the people who answered me. Hope my information help you too.
我采取的方法是不允许操作系统在布局配置更改后重新启动您的活动.为此,请在清单文件中要阻止重新启动的活动中添加此行:
The approach I took was to not allow the OS to restart your activity after the layout configuration change. To accomplish this, add this line within activities that you want to prevent from restarting in your manifest file:
<activity
android:configChanges="orientation|keyboard"
...
>
您可以选择在代码中处理配置更改,以防您想要手动进行一些布局更改,例如从 XML 重新加载新视图.这是通过覆盖 Activity 类中的 onConfigurationChanged() 方法来完成的:
Optionally, you can handle the configuration change in code in case there are some layout changes you want to make manually, such as reloading a new view from XML. This is done by overwriting the onConfigurationChanged() method in your Activity class:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
//Handle config changes here, paying attention to
//the newConfig.orientation value
super.onConfigurationChanged(newConfig);
}
在配置更改列表中添加了|keyboard"
Added "|keyboard" to the list of config changes
这篇关于Android:旋转更改后对话框等恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!