1. 程式人生 > >Android頂部狀態列和底部導航欄高度計算

Android頂部狀態列和底部導航欄高度計算

專案開發中,經常會遇到介面適配的問題,狀態列和導航欄的高度計算,直接影響著App的展示效果,下面就來看一下兩種控制元件高度是如何計算的。

1, 頂部狀態列(status bar)

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

2, 底部導航欄(navigation bar)

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