简体   繁体   English

自定义Android对话框方向更改

[英]Custom Android Dialog orientation change

I have a problem on rotation with custom dialog. 我在使用自定义对话框旋转时遇到问题。

My dialog has separate layouts for portrait and landscape orientations. 我的对话框有纵向和横向的单独布局。 The launching Activities manage their own changes through onConfigurationChanged. 启动的Activity通过onConfigurationChanged管理自己的更改。

The problem is that, when rotation occurs with the dialog visible, it retains the layout it was started with. 问题是,当对话框可见时发生旋转时,它将保留开始时使用的布局。 Is there a way to update the dialog's layout without changes to each Activity that may show it? 有没有一种方法可以更新对话框的布局,而无需更改可能显示它的每个活动?

I'm assuming the Activities use onConfigurationChanged in order to change only their layouts while keeping data, tasks, etc. It would seem silly to have each of them update the Dialog when necessary. 我假设活动使用onConfigurationChanged来仅更改其布局,同时保留数据,任务等。让每个活动在必要时更新对话框似乎很愚蠢。 Makes sense for the Dialog itself to do this - but Dialogs don't have onConfigurationChanged. 对于Dialog本身这样做是有意义的-但是Dialog没有onConfigurationChanged。

Changing your Dialog into a dialog-themed Activity would do what you need. 将您的对话框更改为以对话框为主题的活动将满足您的需求。
It's a workaround, not a solution, though, so I hope someone has a better idea. 不过,这是一种解决方法,而不是解决方案,所以我希望有人有更好的主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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