Question

Is it possible to get the Window object for a particular View (or PopupWindow)?

My app is a keyboard so it is a Service (an InputMethodService), not an Activity. Therefore I cannot use Activity.getWindow(). However, it has Views, so it presumably has a Window too, no? How do I get it?

Thanks in advance...

Was it helpful?

Solution

I found the solution:

    InputMethodService ims;
    ...
    Dialog dialog = ims.getWindow();
    Window window = dialog.getWindow();

or simply:

    Window window = ims.getWindow().getWindow();

(This works with an InputMethodService and is not necessarily applicable to other Services.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top