/**<!--Lang:java--* <!--Lang:java--* @param activity<!--Lang:java--@return > 0 succe ss <= 0 fail<!--Lang:java to */<!--Lang:java--public static int getstatusheight (activity activity) {< ;! ---Lang:java int statusheight = 0;<!--Lang:java--rect localrect = new Rect ();<!--Lang:java-- Activity.getwindow (). Getdecorview (<!--Lang:java--). Getwindowvisibledisplayframe (localrect);<!--Lang: Java--statusheight = localrect.top;<!--Lang:java--and if (0 = = statusheight) {<!--Lang:java--Class <?> localclass;<!--Lang:java--try {<!--Lang:java--Localclass = Class.forName (<!--Lang:jav A--"com.android.internal.r$dimen");<!--Lang:java--and Object localobject = Localclass.newinstance ( );<!--Lang:java to int i5 = Integer.parseint (<!--Lang:java-Localclass.getfield ("Status_b Ar_height "). Get (≪! --Lang:java---Localobject). toString ());<!--Lang:java--statusheight = Activity.getresource S (<!--Lang:java--) getdimensionpixelsize (i5);<!--Lang:java--} catch (Classnotfoundexcepti On e) {<!--Lang:java to E.printstacktrace ();<!--Lang:java--} catch (Illegalaccessexception e) {<!-- Lang:java--E.printstacktrace ();<!--Lang:java--} catch (Instantiationexception e) {<!--Lang:java-- > e.printstacktrace ();<!--Lang:java-to} catch (NumberFormatException e) {<!--Lang:java--E.printsta Cktrace ();<!--Lang:java-to} catch (IllegalArgumentException e) {<!--Lang:java--e.printstacktrace (); &L t;! ---Lang:java} catch (SecurityException e) {<!--Lang:java--e.printstacktrace ();<!--Lang:java--> ; } catch (Nosuchfieldexception e) {<!--Lang:java--e.printstacktrace ();<!--Lang:java--}<!--lang:j Ava--}<!--Lang:java--statusheight;< return!--Lang:java---}
Original Address http://bbs.it-home.org/thread-16887-1-1.html
Get the height of the status bar under Android