SoFunction
Updated on 2025-04-07

Android programming method to get notification bar height

This article describes the method of Android programming to obtain the height of the notification bar. Share it for your reference, as follows:

Here, the height of the notification bar is obtained through the reflection mechanism

The notification bar height is written in the dimen file:

public static int getStatusBarHeight(Context context){
    Class<?> c = null;
    Object obj = null;
    Field field = null;
    int x = 0, statusBarHeight = 0;
    try {
      c = ("$dimen");
      obj = ();
      field = ("status_bar_height");
      x = ((obj).toString());
      statusBarHeight = ().getDimensionPixelSize(x);
    } catch (Exception e1) {
      ();
    }
    return statusBarHeight;
}

I hope this article will be helpful to everyone's Android programming design.