Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the window instance from a view?

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

like image 814
zeus Avatar asked May 30 '17 07:05

zeus


1 Answers

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

like image 61
alijandro Avatar answered Oct 29 '22 19:10

alijandro