In Android development, you often need to know the screen height, width, Status Bar, and Title Bar Height.
Width and height
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);Display display = windowManager.getDefaultDisplay();Point point = new Point();display.getSize(point);SCREEN_WIDTH = point.x;SCREEN_HEIGHT = point.y;System.out.println("SCREEN_WIDTH = " + SCREEN_WIDTH);System.out.println("SCREEN_HEIGHT = " + SCREEN_HEIGHT);
Status Bar Height
If you are working on Rom, you can use the following methods:
int id = com.android.internal.R.dimen.status_bar_height;STATUS_BAR_HEIGHT = (int) getResources().getDimension(id);
The above method only applies to Rom, because the id value has been assigned during compilation, such as COM. android. internal. r. dimen. status_bar_height = 123; the actual code is like this.
int id = 123;STATUS_BAR_HEIGHT = (int) getResources().getDimension(id);
Another method is the improvement of the above method. The Java reflection principle is used to obtain the height.
int id = 0;try {Class<?> cls = Class.forName("com.android.internal.R$dimen");Field field = cls.getField("status_bar_height");id = field.getInt(cls);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (NoSuchFieldException e) {e.printStackTrace();} catch (IllegalArgumentException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace);}