Copy codeThe Code is as follows: package com. aslibra. test;
Import android. app. Activity;
Import android. graphics. Rect;
Import android. OS. Bundle;
Import android. util. Log;
Import android. view. Window;
Import android. widget. ImageView;
Public class test extends Activity {
ImageView iv;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Iv = (ImageView) this. findViewById (R. id. ImageView01 );
Iv. post (new Runnable ()
{
Public void run ()
{
ViewInited ();
}
}
);
Log. v ("test", "= OK = ");
}
Private void viewInited (){
Rect rect = new Rect ();
Window window = getWindow ();
Iv. getWindowVisibleDisplayFrame (rect );
Int statusBarHeight = rect. top;
Int contentViewTop = window. findViewById (Window. ID_ANDROID_CONTENT). getTop ();
Int titleBarHeight = contentViewTop-statusBarHeight;
// Test results: OK after more than 100 MS to run
Log. v ("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
*/
}
The browser obtains the code of the status bar height.
Copy codeThe Code is as follows: Rect visRect = new Rect ();
If (! MBrowserFrameLayout. getGlobalVisibleRect (visRect )){
If (LOGD_ENABLED ){
Log. d (LOGTAG, "showFakeTitleBar visRect failed ");
}
Return;
}
Params. y = visRect. top;