我使用与EditText重叠的PopupWindow处理菜单。
它工作得很好,除了我的PopupWindow被EditText输入法系统中的一些项目覆盖(选择标记,粘贴按钮)。
我的问题是:如何强制对PopupWindow进行z排序,使其显示在这些装饰之上?
这是正在发生的事情的图像。我需要我的PopupWindow (菜单)被绘制在所有东西之上,从而以某种方式告诉WindowManager如何排序窗口。谢谢。

发布于 2012-06-16 07:03:24
我自己找到了一个。
这些装饰是普通的PopupWindow-s,由EditText管理。
任何窗口的Z-排序都是由WindowManager.LayoutParams.type定义的,实际上它定义了窗口的用途。对于弹出窗口,有效范围为FIRST_SUB_WINDOW - LAST_SUB_WINDOW。
App通常不能改变PopupWindow的“类型”,除了使用Java反射调用隐藏函数PopupWindow.setWindowLayoutType(int)和设置所需的窗口类型之外。
结果:

编辑:执行此操作的代码:
Method[] methods = PopupWindow.class.getMethods();
for(Method m: methods){
if(m.getName().equals("setWindowLayoutType")) {
try{
m.invoke(getPopupWindow(), WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
}catch(Exception e){
e.printStackTrace();
}
break;
}
}发布于 2017-09-18 08:14:15
import android.support.v4.widget.PopupWindowCompat;
PopupWindowCompat.setWindowLayoutType(popupWindow, WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);发布于 2017-07-21 10:52:10
public void compatibleSetWindowLayoutType(int layoutType) {
if (Build.VERSION.SDK_INT >= 23) {
setWindowLayoutType(layoutType);
} else {
try {
Class c = this.getClass();
Method m = c.getMethod("setWindowLayoutType", Integer.TYPE);
if(m != null) {
m.invoke(this, layoutType);
}
} catch (Exception e) {
}
}
}https://stackoverflow.com/questions/11058093
复制相似问题