How to get the window instance from a view?

▼魔方 西西 提交于 2020-01-14 19:22:09

问题


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


回答1:


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

After API 19, there is a convenient method to check, view.isAttachedToWindow()




回答2:


You cannot get a window instance from View or WindowManager. But you can get the Display to which the View's window is been attached by calling this method myView.getDisplay()

Edited -you can use View.bringToFront(); or View.bringChildToFront(View child); to reorder the z-index of views.




回答3:


myView.getDisplay() you can use this method to display the View.



来源:https://stackoverflow.com/questions/44256380/how-to-get-the-window-instance-from-a-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!