I. Screen height and Width acquisition method
int screenwidth,screenheight; WindowManager WindowManager = Getwindowmanager (); Display display = Windowmanager.getdefaultdisplay (); ScreenWidth = Display.getwidth (); ScreenHeight = Display.getheight ();
Another kind
Displaymetrics dm = new Displaymetrics (); Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM); int screenwidth = Dm.widthpixels;
Second, the status bar height acquisition method
Rect frame = new rect (); GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (frame); int statusbarheight = Frame.top;
The above method is basically possible, but the following method is more
private int getstatusbarheight () { class<?> c = null; Object obj = null; Field field = NULL; int x = 0; try { c = class.forname ("Com.android.internal.r$dimen"); obj = C.newinstance (); field = C.getfield ("Status_bar_height"); x = Integer.parseint (Field.get (obj). toString ()); Return Getresources (). getdimensionpixelsize (x); } catch (Exception E1) { log.d (TAG, "Get status bar height fail"); E1.printstacktrace (); return;} }
Third, get the height of the title bar
int contenttop = GetWindow (). Findviewbyid (window.id_android_content). GetTop ()//statusbarheight is the height of the above status bar int Titlebarheight = Contenttop-statusbarheight;
Iv. acquisition of Actionbar Heights
int actionbarheight = Getactionbar (). GetHeight ();
Note: If you start using the activity's OnCreate function, you need to put it in runnable, because the height of the control may not be determined at this time.
View Root; Root.post (New Runnable () { @Override public void Run () { //to change body of the implemented methods use File | Settings | File Templates. Getactivitycontentheight (); } });
Android Gets the status bar, title bar, Actionbar, and screen height