如何从视图中获取窗口实例? [英] How to get the window instance from a view?
本文介绍了如何从视图中获取窗口实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过mWindowManager.addview()
在windowManager中添加视图.现在,我想知道是否有可能获得window
实例.他们是myView.getWindowID()
和myView.getWindowToken()
,但是我找不到从其中检索窗口实例的方法
i add a view in the windowManager via mWindowManager.addview()
. Now i would like to know if it's possible to get the window
instance. their is myView.getWindowID()
and myView.getWindowToken()
but i can't find a way to retrieve from it the window instance
推荐答案
如果您的View
已附加到Activity
,则可以这样做.
If your View
has been attached to Activity
, you can do like this.
View view; // your view
if (view.getContext() instanceof Activity) {
Window window = ((Activity) view.getContext()).getWindow();
}
在API 19之后,有一种方便的方法来检查view.isAttachedToWindow()
After API 19, there is a convenient method to check, view.isAttachedToWindow()
这篇关于如何从视图中获取窗口实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文