宽度和高度
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = ();
Point point = new Point();
(point);
SCREEN_WIDTH = ;
SCREEN_HEIGHT = ;
("SCREEN_WIDTH = " + SCREEN_WIDTH);
("SCREEN_HEIGHT = " + SCREEN_HEIGHT);
状态栏高度
如果是做rom工作的同学可以使用如下方法:
int id = .status_bar_height;
STATUS_BAR_HEIGHT = (int) getResources().getDimension(id);
上面方法仅试用做rom的,因为在编译的时候,id的值已经赋值,比如.status_bar_height = 123;那么实际上面的代码就是这样
int id = 123;
STATUS_BAR_HEIGHT = (int) getResources().getDimension(id);
还有一种就是上面方法的改进,利用Java反射原理,获取高度。
int id = 0;
try {
Class<?> cls = ("$dimen");
Field field = ("status_bar_height");
id = (cls);
} catch (ClassNotFoundException e) {
();
} catch (NoSuchFieldException e) {
();
} catch (IllegalArgumentException e) {
();
} catch (IllegalAccessException e) {
);
}