自定义 LinerLayout ;android:theme="@android:style/Theme.Light.NoTitleBar" ;什么加getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 都不行,才有了下面的文章 1.工具类奉上
public class IsBottomBarExitsUtil { /** * Desc: 获取虚拟按键高度 */ public static int getNavigationBarHeight(Context context) { int result = 0; if (hasNavBar(context)) { Resources res = context.getResources(); int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { result = res.getDimensionPixelSize(resourceId); } } LogUtils.e("虚拟键盘高度"+result); return result; } /** * 检查是否存在虚拟按键栏 * * @param context * @return */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static boolean hasNavBar(Context context) { Resources res = context.getResources(); int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android"); if (resourceId != 0) { boolean hasNav = res.getBoolean(resourceId); // check override flag String sNavBarOverride = getNavBarOverride(); if ("1".equals(sNavBarOverride)) { hasNav = false; } else if ("0".equals(sNavBarOverride)) { hasNav = true; } return hasNav; } else { // fallback return !ViewConfiguration.get(context).hasPermanentMenuKey(); } } /** * 判断虚拟按键栏是否重写 * * @return */ private static String getNavBarOverride() { String sNavBarOverride = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { Class c = Class.forName("android.os.SystemProperties"); Method m = c.getDeclaredMethod("get", String.class); m.setAccessible(true); sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys"); } catch (Throwable e) { } } return sNavBarOverride; } }2.在popwindow中的showAtLocation设置Y轴偏移
mPopupWindow.showAtLocation(inflate,Gravity.BOTTOM,0, IsBottomBarExitsUtil.getNavigationBarHeight(getContext()));