问题
I want to find the height of the red square excluding the blue one.
回答1:
To get the height of status bar in your OnCreate method, you can use the following:
int statusBarHeight = 0, totalHeight = 0, contentHeight = 0;
int resourceId = Resources.GetIdentifier ("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = Resources.GetDimensionPixelSize (resourceId);
totalHeight = Resources.DisplayMetrics.HeightPixels;
contentHeight = totalHeight - statusBarHeight;
}
The variable contentHeight now has the value you are looking for.
来源:https://stackoverflow.com/questions/36927534/android-status-bar-height-in-xamarin-android