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;

 

相关文章:

  • 2021-04-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2021-09-15
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2021-11-14
相关资源
相似解决方案