views:

47

answers:

1

Hi

Is there a way to retrieve the height (in pixels) taken by the application title and the top bar (the one containing the clock, signal information etc...)

Thanks

+2  A: 

Create a sample android program. Android would have created a Linearlayout by default in your main.xml for you. Provide an ID to that layout and use it

final LinearLayout ll1=(LinearLayout)findViewById(R.id.ll1);
ll1.post(new Runnable()
    {
       public void run()
         {
            Rect rect= new Rect();
            Window window= getWindow(); ll1.getWindowVisibleDisplayFrame(rect);
            int statusBarHeight= rect.top;
            Log.e("", "ht of sb  bar is "+statusBarHeight);
            int contentViewTop= window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
            int titleBarHeight= contentViewTop - statusBarHeight;
            Log.e("", "ht of title bar is "+titleBarHeight);
         }
    }); 

http://andmobidev.blogspot.com/2010/01/getting-height-of-status-and-title-bar.html

Rahul
Thanks for that ... Wished that information was more easily available in google documentation.
jyavenard
This is WRONG. You are assuming that the status bar won't change height or move. You can't make such an assumption. The correct thing to do is write your app to do correct layout, by putting your view in the activity and letting the layout system give it a size.
hackbod