问题
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