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)