[Android] 獲取系統頂部狀態欄(Status Bar)與底部導航欄(Navigation Bar)的高度


Android一些設備都有上下兩條bar,我們可以獲取這些bar的信息。下面放上獲取高度的代碼。代碼注釋和其他方法有空再放。

原文地址請保留http://www.cnblogs.com/rossoneri/p/4142962.html

獲取頂部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;
}

獲取底部 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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM