Created
October 13, 2014 07:03
-
-
Save interchen/fa4624639099e448b351 to your computer and use it in GitHub Desktop.
android get statusbar height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getStatusBarHeight(Context context){ | |
Class<?> c = null; | |
Object obj = null; | |
Field field = null; | |
int x = 0, statusBarHeight = 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()); | |
statusBarHeight = context.getResources().getDimensionPixelSize(x); | |
} catch (Exception e1) { | |
e1.printStackTrace(); | |
} | |
return statusBarHeight; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment