Android得到状态栏和标题栏的高度

// 得到屏幕的宽
			displayMetrics = getResources().getDisplayMetrics();
			screenWidth = displayMetrics.widthPixels;
			// 得到标题栏和状态栏的高度
			Rect rect = new Rect();
			Window window = getWindow();
			mImageView.getWindowVisibleDisplayFrame(rect);
			int statusBarHeight = rect.top;
			int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
			int titleBarHeight = contentViewTop - statusBarHeight;
			// 得到屏幕的高
			screenHeight = displayMetrics.heightPixels- (statusBarHeight + titleBarHeight);

你可能感兴趣的:(Android得到状态栏和标题栏的高度)