Search code examples
androidstatusbarime

Height of status bar in Android with no Activity (IME)


I am trying to determine the height to the status bar in Android, . I have found answers, but all seem to rely on the Activity object ( e.g., activity.getWindow() ). However, I am developing an input method, which does not have an associated activity object.

Any ideas how I can do this in an IME?


Solution

  • This has been answered in other posts. Here and a response linked to here.

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