Home > Tricks & Tips > Get Window Status Bar and Title Bar Height Size

Get Window Status Bar and Title Bar Height Size

Size of Bar

Size of Bar

This is an interesting tip🙂 to get the height size of status bar and title bar, assuming that they are both on the top of screen.

    public void onCreate(Bundle savedInstanceState) {

        tvContent = (TextView)findViewById(R.id.tvContent);
        tvContent.postDelayed(new Runnable() {

			public void run() {
				 String display = String.format("Status Bar Height = %d\nTitle Bar Height = %d", getStatusBarHeight(), getTitleBarHeight());

		}, 2000);


    public int getStatusBarHeight() {
    	Rect r = new Rect();
    	Window w = getWindow();
    	return r.top;

    public int getTitleBarHeight() {
    	int viewTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
    	return (viewTop - getStatusBarHeight());

The reason why getting directly inside onCreate() method doesnot work is because the view is being measured; so it’s better to retrieve the size after finishing measuring. In this case, I attach a handler to the TextView and run after 2 seconds delay. You also can run on a Listener as well.

Pete Houston

Categories: Tricks & Tips Tags: , , , , ,
  1. Aasha
    July 4, 2013 at 11:52 pm

    Thanks..:) Helped!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: