Home > Mobile >  Is there any difference between the two writing?
Is there any difference between the two writing?

Time:09-21

To obtain the status bar height, two writing
Colleague:
 
Private static Boolean USE_CUSTOM_STATUS_BAR_HEIGHT=true;
Private static int statusBarHeight=1;
Public static int getStatusBarHeight Activity (Activity) {
If (statusBarHeight!=1 & amp; & ! USE_CUSTOM_STATUS_BAR_HEIGHT) {
Return statusBarHeight;
}
Try {
If (the activity!=null & amp; & ! Activity. IsFinishing ()) {
The Rect the Rect=new the Rect ();
Windows Window=activity. GetWindow ();
Window. GetDecorView (.) getWindowVisibleDisplayFrame (the rect);
StatusBarHeight=the rect. Top;
USE_CUSTOM_STATUS_BAR_HEIGHT=false;
}
} the catch (Exception e) {
LOGGER. D (TAG, "getStatusBarHeight Exception", e);
}
If (USE_CUSTOM_STATUS_BAR_HEIGHT) {
StatusBarHeight=DeviceUtils. FromDipToPx (ApplicationContext, 20).
}
Return statusBarHeight;
}


I wrote:
 
Private static int statusBarHeight=DeviceUtils. FromDipToPx (ApplicationContext, 20).
Public static int getStatusBarHeight Activity (Activity) {
If (activity==null | | activity. IsFinishing) {
Return statusBarHeight;
} else {
The Rect rectgle=new the Rect ();
Windows Window=activity. GetWindow ();
Window. GetDecorView (.) getWindowVisibleDisplayFrame (rectgle);
StatusBarHeight=rectgle. Top;
Return rectgle. Top;
}
}

From the perspective of value, both for the status bar height method is there a difference?
  • Related