I use following code to show a small popup:
public static PopupWindow showImportMenu(Activity activity, View anchor, PopupWindowClickListener onClickListener)
{
LayoutInflater inflater = LayoutInflater.from(activity);
PopupImportBinding binding = DataBindingUtil.inflate(inflater, R.layout.popup_import, null, false);
if (!RootTools.isRootAvailable())
binding.llImportRootMethod.setVisibility(View.GONE);
PopupWindow popupWindow = new PopupWindow(activity, null, R.attr.popupMenuStyle);
popupWindow.setFocusable(true);
popupWindow.setContentView(binding.getRoot());
popupWindow.setOutsideTouchable(true);
PopupWindowCompat.showAsDropDown(popupWindow, anchor, 0, 0, Gravity.BOTTOM);
View.OnClickListener clickListener = new View.OnClickListener()
{
@Override
public void onClick(View view)
{
onClickListener.onClick(popupWindow, view);
}
};
binding.llImportDefault.setOnClickListener(clickListener);
binding.llImportRootMethod.setOnClickListener(clickListener);
binding.llImportHTCFromContacts.setOnClickListener(clickListener);
binding.llImportManual.setOnClickListener(clickListener);
return popupWindow;
}
This works on a lot of devices but on some rare devices it does not work, like:
- Android 5.1.1 root slim rom
- maybe others... until now, I don't know more about other devices
I got the feedback that no popup is shown. Does anyone know why this is not working on the above mentioned device? And what I can do to make it work on this device as well?
EDIT
It seems like it's not clear that what I want is following:
- use
showAsDropDown
notshowAtLocation
or similar, I never saw this problem withshowAtLocation
yet - my solution is working on nearly all devices, it seems to be a phone/rom specific problem, maybe it's not even solvable as it COULD be a bug in the device as well => if someone knows of such a bug, telling me would be fine as well
- I don't want to use a dialog (or anything else) instead, that's not answering my question. I currently use a
BottomSheet
which is fine for me, but still I would like to know if the problem can be solved and somehow handled
showAtLocation
is working as long as you provide a background drawable but I have not tried it on this special device because the user is not answering anymore. I want to have the advantages ofshowAsDropDown
because my popup may need to be drawn on top, left, rigt, bottom or even overlaying the anchor depending on scroll position and screen size. Doing everything manually probably will work, but that's just an assumption, because in another app I never had problems with thePopupWindow
and there I useshowAtLocation
... – TragacanthshowAtLocation()
does not help.PopupWindow
is still not displayed. This is an Android 5.0.2 device from Vivo. – Faina