Created
April 6, 2015 02:41
-
-
Save hamakn/8939eb68a920a6d7a498 to your computer and use it in GitHub Desktop.
Android: Get height of status, action, navigation bar (pixels)
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
// status bar height | |
int statusBarHeight = 0; | |
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); | |
if (resourceId > 0) { | |
statusBarHeight = getResources().getDimensionPixelSize(resourceId); | |
} | |
// action bar height | |
int actionBarHeight = 0; | |
final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes( | |
new int[] { android.R.attr.actionBarSize } | |
); | |
actionBarHeight = (int) styledAttributes.getDimension(0, 0); | |
styledAttributes.recycle(); | |
// navigation bar height | |
int navigationBarHeight = 0; | |
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); | |
if (resourceId > 0) { | |
navigationBarHeight = resources.getDimensionPixelSize(resourceId); | |
} |
How you found these identifiers? Plz if you can share.
You can read the android open source project , it contains the java & xml files of the whole system
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JNI translation for getting status bar height: (tested with a NativeActivity app)