Statusbar height in Android

Source: Internet
Author: User

Team boss asked me to find out how to get the height of statusbar, but I couldn't find the information about statusbar height in the android SDK. In fact, it is described in the XML file of the android framework, the height is 25dp (in frameworks \ base \ core \ res \ values \ dimens. XML), but Google is not made public in the SDK. I don't know why. If the mobile phone manufacturer modifies this height, I don't know how to obtain this parameter from the SDK.

In fact, most mobile phones do not modify this parameter value (I do not know whether there is a mobile phone or not), because this will change a lot of things, for example, the Icon size and font size on statusbar must be changed. It is actually usableProgramThe value obtained is not in the unit of DP, but PX, provided that the value can be obtained only through view, some programs that do not contain views do not know how to obtain them. I hope you can help me with this.

Attached with the view to get the statusbar heightCode(The Code cannot be placed in the oncreate method ):

Public class calculatestatusbar extends activity {/** called when the activity is first created. */private textview TV; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); TV = (textview) This. findviewbyid (R. id. mytextview); TV. post (New calculater ();} class calculater implements runnable {public void run () {rect = new rect (); getwindow (). getdecorview (). getwindowvisibledisplayframe (rect); int statusbarheight = rect. top; system. out. println ("statusbarheight:" + statusbarheight );}}}

The running result depends on the resolution of the mobile phone used. The specific result is as follows:

Ldpi: 19px (25*0.75)

Mdpi: 25px (25*1.00)

Hdpi: 38px (25*1.50)

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.