这个问题之前已经回答过了.Height of statusbar?
更新::
当前方法:
好的,状态栏的高度取决于屏幕尺寸,例如,在屏幕尺寸为240×320的设备中,状态栏高度为20px,对于屏幕尺寸为320×480的设备,状态栏高度为25px,对于尺寸为480 x 800的设备,状态栏高度必须为38px
因此,我建议使用此脚本来获取状态栏高度
代码语言:javascript运行复制Rect rectangle = new Rect();
Window window = getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarHeight = rectangle.top;
int contentViewTop =
window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight= contentViewTop - statusBarHeight;
Log.i("*** Elenasys :: ", "StatusBar Height= " + statusBarHeight + " , TitleBar Height = " + titleBarHeight); (旧方法)要获取Activity的onCreate()方法上状态栏的高度,请使用以下方法:
代码语言:javascript运行复制public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}