问题描述:
使用popupWindow.showAtLocation,导致侵入到华为虚拟键盘里面

针对这样的情况,我们可以考虑获取到底部的虚拟键盘的高度,当然了在获取虚拟键盘的高度的时候,需要判断是否含有虚拟键盘
解决办法是加多一个判断
/**
* @date: 2019/3/14 0014
* @author: gaoxiaoxiong
* @description:显示popuWindow
**/
public void showPowuWindow() {
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
} else {
//判断是否有虚拟键盘,如果有就新增Y轴的高度,否则就是0,解决华为虚拟按钮挡住popuwindow
if (ScreentUtil.checkDeviceHasNavigationBar(mContext)){
popupWindow.showAtLocation(drowView, Gravity.BOTTOM,0,ScreentUtil.getVirtualBarHeight(mContext));
}else {
popupWindow.showAtLocation(drowView, Gravity.BOTTOM,0,0);
}
}
}
获取虚拟键盘高度,判断是否含有虚拟键盘
/**
* @date: 2019/3/28 0028
* @author: gaoxiaoxiong
* @description:获取底部虚拟导航键的高度
**/
public static int getVirtualBarHeight(Context context) {
int vh = 0;
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
try {
@SuppressWarnings("rawtypes")
Class c = Class.forName("android.view.Display");
@SuppressWarnings("unchecked")
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
vh = dm.heightPixels - display.getHeight();
} catch (Exception e) {
e.printStackTrace();
}
return vh;
}
/**
* 获取是否有虚拟按键
* 通过判断是否有物理返回键反向判断是否有虚拟按键
* @param context
* @return
*/
public static boolean checkDeviceHasNavigationBar(Context context) {
boolean hasMenuKey = ViewConfiguration.get(context)
.hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap
.deviceHasKey(KeyEvent.KEYCODE_BACK);
if (!hasMenuKey & !hasBackKey) {
// 做任何你需要做的,这个设备有一个导航栏
return true;
}
return false;
}

网友评论