通过反射机制获取状态栏的高度

来源:互联网 发布:c语言怎么自定义函数 编辑:程序博客网 时间:2024/05/16 13:07
  1.       Class<?> c = null;
  2.       Object obj = null;
  3.       Field field = null;
  4.       int x = 0, sbar = 0;
  5. try {
  6.         c = Class.forName("com.android.internal.R$dimen");
  7.         obj = c.newInstance();
  8.         field = c.getField("status_bar_height");
  9.         x = Integer.parseInt(field.get(obj).toString());
  10.         sbar = getResources().getDimensionPixelSize(x);
  11. } catch (Exception e1) {
  12.         loge("get status bar height fail");
  13.         e1.printStackTrace();
  14. }  
原创粉丝点击