As shown in the following code:
[Java]View Plaincopy
- private int Getstatusbarheight () {
- class<?> c = null ;
-
- object obj = null ;
-
- field field = null ;
-
- int x = 0 , sbar = 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 ());
- Sbar = GetContext (). Getresources (). getdimensionpixelsize (x);
-
- } catch
- E1.printstacktrace ();
- }
-
- return sbar;
- }
This is a way for a cow to come up with. The method is a bit two, the main principle is to find dimen from the system R file, the inner class, and then through the reflection to get dimen in the value of Status_bar_height, this value is actually the resource ID, and then through the GetResource method to get the value corresponding to the ID, It's so perfect, it's impeccable! This method should also apply to the values of other system fields.
There are many ways to introduce the status bar on the network, but there are some limitations. Like what:
Status Bar Height
After the Getwindowvisibledisplayframe (Rect outrect) value of the view is Outrect, Outrect.top () is the status bar height
Title Height
Outrect.height ()-view.getheight () is the caption height after the view's Getwindowvisibledisplayframe (Rect outRect1) value Outrect.
This method only applies when the view has been drawn, so that the corresponding value can be obtained, and if I'm not mistaken, the view should also fill the screen. But in many cases we need to get this value before the view has been drawn, and this method is not reliable at all.
Source: >
From for notes (Wiz)