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; }