1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public static boolean hasNavigationBarShow(Activity activity) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return false; } WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getRealMetrics(outMetrics); int heightPixels = outMetrics.heightPixels; int widthPixels = outMetrics.widthPixels; outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); int heightPixelsContent = outMetrics.heightPixels; int widthPixelsContent = outMetrics.widthPixels; int h = heightPixels - heightPixelsContent; int w = widthPixels - widthPixelsContent; return w > 0 || h > 0; }
public static int getNavigationBarHeight(Context context) { return getSystemComponentDimen(context, "navigation_bar_height"); }
public static int getSystemComponentDimen(Context context, String dimenName) { int statusHeight = -1; try { Class<?> clazz = Class.forName("com.android.internal.R$dimen"); Object object = clazz.newInstance(); String heightStr = clazz.getField(dimenName).get(object).toString(); int height = Integer.parseInt(heightStr); statusHeight = context.getResources().getDimensionPixelSize(height); } catch (Exception e) { e.printStackTrace(); } return statusHeight; }
|