requestWindowFeature(Window.FEATURE_NO_TITLE);
// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
a. 得到statusBarHeight:
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
b.得到TitleBar高度
int contentViewTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight = contentViewTop - statusBarHeight;
c.得到屏幕可显示区域高度
public static int getDisplayHeight(Context context) {
Rect frame = new Rect();
((Activity)context).getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = getStatusBarHeight(context);
//得到屏幕的整个高度
int mFullDisplayHeight = ((Activity)context).getWindowManager().getDefaultDisplay()
.getHeight();
//得到可显示屏幕高度
int mDisplayHeight = mFullDisplayHeight - statusBarHeight - titleBarHeight;
// Log.d("TEST", "status bar height:" + statusBarHeight);
// Log.d("TEST", "mFullDisplayHeight====" + mFullDisplayHeight);
return mDisplayHeight;
}
verdion> 3.2
public static void getDisplaySize(Context context) {
Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Log.d("Display sise", "width:" + width + "---height:" + height);
}
private void getScreenSize() {
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int screenWidth = metric.widthPixels;
int screenHeight = metric.heightPixels;
Log.d("Screen", "width: =" + screenWidth + " Height: =" + screenHeight);
}
// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
a. 得到statusBarHeight:
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
b.得到TitleBar高度
int contentViewTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight = contentViewTop - statusBarHeight;
c.得到屏幕可显示区域高度
public static int getDisplayHeight(Context context) {
Rect frame = new Rect();
((Activity)context).getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = getStatusBarHeight(context);
//得到屏幕的整个高度
int mFullDisplayHeight = ((Activity)context).getWindowManager().getDefaultDisplay()
.getHeight();
//得到可显示屏幕高度
int mDisplayHeight = mFullDisplayHeight - statusBarHeight - titleBarHeight;
// Log.d("TEST", "status bar height:" + statusBarHeight);
// Log.d("TEST", "mFullDisplayHeight====" + mFullDisplayHeight);
return mDisplayHeight;
}
verdion> 3.2
public static void getDisplaySize(Context context) {
Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Log.d("Display sise", "width:" + width + "---height:" + height);
}
private void getScreenSize() {
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int screenWidth = metric.widthPixels;
int screenHeight = metric.heightPixels;
Log.d("Screen", "width: =" + screenWidth + " Height: =" + screenHeight);
}