Android.view.WindowManager
lastmod 2018-08-17created 2016-05-162 edits
Getting the Android Density
Get screen info...
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// 이 값은 0.75, 1.0, 1.5, 2.0 등의 값을 가지며
// 이 값에 dp을 곱하면 pixel 단위의 값을 구할 수 있습니다.
float dpi = metrics.density;
Getting the Android screen size
You can get the screen size as shown below. The unit is pixels. //(Gets the size of the display, in pixels.)//
int width = getWindowManager().getDefaultDisplay().getWidth();
int height = getWindowManager().getDefaultDisplay().getHeight();
Getting Height of Status and Title Bar
The height of the title bar and status bar can be found as follows.
Rect rect= new Rect();
// ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight= contentViewTop - statusBarHeight;