Android 获得状态栏的高度

来源:互联网 发布:淘宝关键词排列顺序 编辑:程序博客网 时间:2024/06/05 05:30
private int getStatusBarHeight(Context context) {
      Class< ?> c = null;
      Object obj = null;
      Field field = null;
      int x = 0, sbar = 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());
          sbar =context.getResources().getDimensionPixelSize(x);
      } catch (Exception e1) {
         e1.printStackTrace();
      }
      return sbar;
    }
0 0