Get the screen, status bar, title bar height
@Override
Public void onwindowfocuschanged (boolean hasfocus) { Super. onwindowfocuschanged (hasfocus); if (hasfocus) { //Screen width high-contains the status bar. Note that Huawei's mobile phone does not contain the following "home button that column", such as the 1920 screen only 1794 Point point = new point (); Display disp = this. Getwindowmanager (). Getdefaultdisplay (); disp.getsize (point); //Remove the height after the status bar. From these two data can calculate the 1920*1080 mobile phone status bar height of 75, that is, "25*3", this value is generally fixed! rect rect = new rect (); This . GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (rect); //Remove the height of the status bar and title bar, this value is the same as the status bar, which is also rect rect2 = new rect (); This . GetWindow (). Findviewbyid (Window. Id_android_content). Getdrawingrect (RECT2); Log. I ("BQT", point.) y + "---" + rect.height () + "---" + rect2.height ()); //"Queer 1920-1848-1776" "Huawei 1794-1719-1644 " } }
Summary of information method for obtaining screen width higher
Method 1, obsolete.
int SCREENWIDTH =&NBSP, getwindowmanager () Span style= "FONT-SIZE:11PT; Color:windowtext; font-family: Microsoft ya black; Line-height:1.6em; " >.getdefaultdisplay (). getwidth () Span style= "FONT-SIZE:11PT; Color:windowtext; font-family: Microsoft ya black; Line-height:1.6em; " >;
int screenheight = Getwindowmanager () . Getdefaultdisplay (). getheight () ; Log. e ("BQT", "screenwidth=" + screenwidth + "; screenheight= " + screenheight); //screenwidth=1080 or 720; screenheight=1920 or
Method 2,api13 (3.2) before you can use
Point outsize = New Point ();
Getwindowmanager (). Getdefaultdisplay (). GetSize (outsize); int screenwidth = outsize. x; int screenheight = outsize. y; Log. e ("BQT", "screenwidth=" + screenwidth + "; screenheight= " + screenheight); //screenwidth=1080 or 720; screenheight=1920 or
Method 3, can be compatible with the lower version
Displaymetrics DM = getresources (). Getdisplaymetrics ();
int screenwidth = DM.widthpixels; //Screen width px int screenheight = DM.heightpixels; //Screen high px Log. e ("BQT", "screenwidth=" + screenwidth + "; screenheight= " + screenheight); //screenwidth=1080; screenheight=1920 float density = dm.density; //Pixel scale: 0.75/1.0/1.5/2.0 int densitydpi = DM.densitydpi; //pixels per inch: 120/160/240/320 Log. e ("BQT" + "Displaymetrics", "density=" + density + "; densitydpi= " + densitydpi); //density=3.0 or 2.0; densitydpi=480 or float xdpi = DM.xdpi; float ydpi = DM.ydpi; Log. e ("BQT" + "Displaymetrics", "xdpi=" + xdpi + "; ydpi= " + ydpi); //xdpi=160.42105; ydpi=159.89508;
From for notes (Wiz)
Get status bar, title bar, screen height