Reliably get height of status bar to solve KitKat translucent navigation issue

后端 未结 4 1297
轻奢々
轻奢々 2020-12-14 01:45

I am experimenting with the new Android 4.4 translucent navigation bars and would like to set the navigation bar as translucent using the FLAG_TRANSLUCENT_NAVIGATION

4条回答
  •  天涯浪人
    2020-12-14 01:57

    public int getStatusBarHeight() {
          int result = 0;
          int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
          if (resourceId > 0) {
              result = getResources().getDimensionPixelSize(resourceId);
          }
          return result;
    }
    

    Use the above code in the onCreate method. Put it in a contextWrapper class. http://mrtn.me/blog/2012/03/17/get-the-height-of-the-status-bar-in-android/

提交回复
热议问题