1 public static int getStatusBarHeight(Context context){ 2 Class<?> c = null; 3 Object obj = null; 4 Field field = null; 5 int x = 0, statusBarHeight = 0; 6 try { 7 c = Class.forName("com.android.internal.R$dimen"); 8 obj = c.newInstance(); 9 field = c.getField("status_bar_height"); 10 x = Integer.parseInt(field.get(obj).toString()); 11 statusBarHeight = context.getResources().getDimensionPixelSize(x); 12 } catch (Exception e1) { 13 e1.printStackTrace(); 14 } 15 return statusBarHeight; 16 }
1 //获取到状态栏的高度 2 Rect frame = new Rect(); 3 getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); 4 int statusBarHeight = frame.top;