PopupWindow-在某些设备上不起作用 [英] PopupWindow - not working on a few devices
本文介绍了PopupWindow-在某些设备上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码显示一个小的弹出窗口:
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
- 也许是其他人...直到现在,我对其他设备一无所知
我得到的反馈是没有显示弹出窗口.有谁知道为什么在上面提到的设备上不起作用?我该怎么做才能使其在该设备上正常工作?
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?
编辑
似乎不清楚我想要的是什么
It seems like it's not clear that what I want is following:
- 使用
showAsDropDown
而不是showAtLocation
或类似的字体,我还没见过showAtLocation
出现此问题 - 我的解决方案几乎可以在所有设备上运行,这似乎是特定于电话/ROM的问题,也许甚至无法解决,因为它也可能是设备中的错误=>如果有人知道这样的错误,告诉我也很好
- 我不想使用对话框(或其他任何对话框),这没有回答我的问题.我目前使用的
BottomSheet
对我来说很好,但是我仍然想知道问题是否可以解决并以某种方式解决
- 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
推荐答案
在运行5.1.1的Nexus 7(不是2012)上,我遇到了同样的问题.最后通过添加以下行对其进行了修复:
I got the same problem on a Nexus 7 (not 2012) running the 5.1.1. It is finally fixed by adding this line:
popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
这篇关于PopupWindow-在某些设备上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文