如何将一个DialogFragment提升到另一个之上? [英] How to raise one DialogFragment above another?

查看:110
本文介绍了如何将一个DialogFragment提升到另一个之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我有几个对话框片段,它们是对可以按任何顺序到达的消息和事件的响应而显示的.通常,显示的最后一个对话框将位于顶部.是否有办法在现有片段下面显示一个对话框片段,或在显示后更改其z顺序?

Say I have several dialog fragments that are shown in response to messages and events that can arrive in any order. Normally, the last dialog shown will be on top. Is there a way to show a dialog fragment under an existing one, or change their z-order after they are shown?

对于我的应用程序,一次显示多个对话框应该很少见,但是有可能发生.只要有一个可见的对话框,就应该始终将其放在顶部.

It should be pretty rare for my app to show more than one dialog at a time, but it could happen. There is one particular dialog that should always be on top whenever it's visible.

推荐答案

对话框会创建一个应用程序子窗口.Android的窗口管理器( WindowManagerService)会根据其类型自动计算窗口的z顺序并将其存储在

A dialog creates an application sub-window. Android's window manager (WindowManagerService) automatically computes window's z-order depending on its type and stores it in WindowState's mLayer field. Internal Android classes have access to this field and change window's z-order sometimes, but this API is not exposed to Android SDK. So it seems that the only way to affect dialog's z-order is to recreate it.

我上面写的所有内容只是对Android源代码进行简短调查的结果,因此我可能是错的.也许有一些骇人听闻的方法可以使用反射并访问私有字段和方法来完成您想要的事情.但是我不确定尝试这样做是否是个好主意.我认为最好只有一个对话框甚至活动,并管理其中的片段.

Everything I wrote above is just a result of a brief investigation of Android's source code so I may be wrong. And maybe there's some hacky way to do what you want using reflection and accessing private fields and methods. But I'm not sure it's a good idea to try and do it. In my opinion it would be better to have just a single dialog or even activity, and manage fragments within it.

这篇关于如何将一个DialogFragment提升到另一个之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆