// Obtain the screen width public static int getscreenwidth (context) {windowmanager WM = (windowmanager) context. getsystemservice (context. window_service); displaymetrics outmetrics = new displaymetrics (); WM. getdefadisplay display (). getmetrics (outmetrics); Return outmetrics. widthpixels;}/*** obtain screen height ** @ Param context * @ return */public static int getscreenheight (context) {windowmanager WM = (Window Manager) context. getsystemservice (context. window_service); displaymetrics outmetrics = new displaymetrics (); WM. getdefadisplay display (). getmetrics (outmetrics); Return outmetrics. heightpixels;}/*** get the height of the status bar ** @ Param context * @ return */public static int getstatusheight (context) {int statusheight =-1; try {class <?> Clazz = Class. forname ("com. android. internal. r$ dimen "); object = clazz. newinstance (); int Height = integer. parseint (clazz. getfield ("status_bar_height "). get (object ). tostring (); statusheight = context. getresources (). getdimensionpixelsize (height);} catch (exception e) {e. printstacktrace ();} return statusheight ;}
How to obtain screen width, height, and Status Bar Height