Android获取系统顶部状态栏(Status Bar)和底部导航栏(Navigation Bar)的高度

1、Android系统顶部状态栏的高度获取:

  private int getStatusBarHeight() {
        Resources resources = getResources();
        int resourceId = resources.getIdentifier("status_bar_height", "dimen","android");
        int height = resources.getDimensionPixelSize(resourceId);
        Log.e(TAG, "Status height:" + height);
        return height;
    }  

2、底部导航栏的高度获取:

  private int getNavigationBarHeight() {
        Resources resources = getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android");
        int height = resources.getDimensionPixelSize(resourceId);
        Log.e(TAG, "Navi height:" + height);
        return height;
    }

3、获取屏幕宽高:

/**
 * 获取屏幕宽高
 */
WindowManager wm = getWindowManager();
int mWidth = wm.getDefaultDisplay().getWidth();
int mHeight = wm.getDefaultDisplay().getHeight();

4、屏幕宽高是不包括底部导航栏的高度的,但包括状态栏的高度

你可能感兴趣的:(Android获取系统顶部状态栏(Status Bar)和底部导航栏(Navigation Bar)的高度)