0

I want to get the title bar height (not the status bar)

I need this in order to know the real height the app can use.

I saw on SO some code and I tried it and it returned height=0.

So, I did some more search and I found that I have to put it inside a runnable and call it with a post-delayed.

Here is the code:

    Handler mHandler = new Handler();

    Runnable r = new Runnable() {  
        @Override  
        public void run() {  
            Rect frame = new Rect();  
            getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
            int titleHeight = frame.top;  
            Log.d(TAG, titleHeight); 
        }  
    };  

    mHandler.postDelayed (r, 200);

This is working. The Log.D shows the correct height, But now there is a new problem. I cannot use the titleHeight variable for further programming inside my onCreate.

What to do?

Thanks, AJ

rnrneverdies
  • 15,243
  • 9
  • 65
  • 95
AJ Gottes
  • 401
  • 1
  • 3
  • 15
  • possible duplicate of [Size of android notification bar and title bar?](http://stackoverflow.com/questions/3600713/size-of-android-notification-bar-and-title-bar) – rnrneverdies Nov 18 '14 at 23:38

1 Answers1

0

The scope of that variable is inside the run method. If you want to reference that variable, you should change it to a larger scope (define it outside of this method).

Booger
  • 18,579
  • 7
  • 55
  • 72