SoFunction
Updated on 2025-04-09

Small examples of getting status bar and taskbar height on Android


package ;

import ;
import ;
import ;
import ;
import ;
import ;

public class test extends Activity {
  ImageView iv;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView();

    iv = (ImageView) (.ImageView01);
    (new Runnable()
    {
      public void run()
      {
        viewInited();
      }
    }
    );
    ("test", "== ok ==");
  }

  private void viewInited(){
    Rect rect= new Rect();
    Window window= getWindow();
    (rect);
    int statusBarHeight= ;
    int contentViewTop= (Window.ID_ANDROID_CONTENT).getTop();
    int titleBarHeight= contentViewTop - statusBarHeight;
//Test results: After ok, it only took more than 100 ms to run
    ("test", "=-init-= statusBarHeight="+statusBarHeight+
        " contentViewTop="+contentViewTop+
        " titleBarHeight="+titleBarHeight);   
  }

  /*
   * 07-14 02:36:48.449: VERBOSE/test(1385): == ok ==
   * 07-14 02:36:48.558: VERBOSE/test(1385): =-init-= statusBarHeight=25 contentViewTop=50 titleBarHeight=25
   */
}