1. 程式人生 > >android 程式碼獲取狀態列高度

android 程式碼獲取狀態列高度

專案中有需求要獲取到狀態列的高度,
故記錄一下程式碼的實現

/**
* 利用反射獲取狀態列高度
* @return
*/
public int getStatusBarHeight() {
  int result = 0;
  //獲取狀態列高度的資源id
  int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
  if (resourceId > 0) {
      result = getResources().getDimensionPixelSize(resourceId);
  }
  return result;
}