当前位置: 代码迷 >> Android >> Android - 状态栏高度
  详细解决方案

Android - 状态栏高度

热度:38   发布时间:2016-04-28 01:10:36.0
Android -- 状态栏高度

干货

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 = getResources().getDimensionPixelSize(x);} catch(Exception e1) {    loge("get status bar height fail");    e1.printStackTrace();}

 

下面代码不要放在onCreate中,否则获取状态栏高度为0

Rect frame = new Rect();getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);int statusBarHeight = frame.top;

我是天王盖地虎的分割线

  相关解决方案