A small example of how Android gets the status bar and taskbar height

Source: Internet
Author: User

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;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.