Android 获取系统顶部状态栏高度和底部导航栏的高度

时间:2022-11-26 14:31:41
  • System Bar
    在Android4.0 (API Level 14)及更高版本中,System BarStatus Bar(位于顶部)Navigation Bar(位于底部)组成。

  • 获取顶部(Status Bar) 高度

    public int getStatusBarHeight() {

    Resources resources = mActivity.getResources();

    int resourceId = resources.getIdentifier("status_bar_height","dimen","android");

    int height = resources.getDimensionPixelSize(resourceId);

    Log.v("status bar>>>", "height:" + height);

    return height;

}
  • 获取底部 (Navigation Bar) 高度
public int getNavigationBarHeight() {

    Resources resources = mActivity.getResources();

    int resourceId=resources.getIdentifier("navigation_bar_height","dimen","android");

    int height = resources.getDimensionPixelSize(resourceId);

    Log.v("navigation bar>>>", "height:" + height);

    return height;

}