Android 中一种判断 Navigation Bar 位置的方法

  public boolean isNavigationBottom() {
        WindowManager wm;
        Display display;
        DisplayMetrics realSize;
        DisplayMetrics windowSize;

        realSize = new DisplayMetrics();
        windowSize = new DisplayMetrics();
        wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        display = wm.getDefaultDisplay();

        display.getRealMetrics(realSize);
        display.getMetrics(windowSize);

        if (windowSize.heightPixels != realSize.heightPixels)
            return true;
        else
            return false;
    }

getRealMetrics()getRealSize()的功能几乎一样。

see also: get physical screen size