一个有效的获取状态栏高度的方法,很早之前找的了,记录在此。(原地址找不到了)
Class<?> c = null;
Object obj = null;
Field field = null;
int x = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
return getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
e1.printStackTrace();
Log.e(TAG, "getbarheight error");
return 46;
}
本文介绍了一种使用Java代码获取Android设备状态栏高度的有效方法。通过反射机制调用系统的资源文件,此方法能够准确地获取到状态栏的高度值。
1872

被折叠的 条评论
为什么被折叠?



