Search code examples
androidandroid-studioandroid-popupwindow

Android studio PopupWindow works in emulator but not on device


PopupWindow shows and works perfectly in AVD but not on a real device.

This is the function that is supposed to create the popup:
http://pastebin.com/jabHVp2c

What I tried:
I made sure that onClick is being called, and it is.
I made sure no other View in the hierarchy is clipping, or even clickable, just in case.
The problem seems to have appeared after I added animations to the popup, but commenting them out makes no difference, and as mentioned, it does work in the emulator as expected.

App API level is 15, AVD API level is 23, device is LG G3 running API 23.


Solution

  • popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
    popupWindow.showAtLocation(rootView, Gravity.CENTER, 0, 0);
    popupWindow.update();
    

    This solves the problem. Apparently the "update()" is required, though it works without it on the emulator, and I have no idea how it worked on the device several version before.

    Hope this helps someone.