Created
April 15, 2015 06:28
-
-
Save JetXing/664a7f54c437b44ab73a to your computer and use it in GitHub Desktop.
get the height of actionBar
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
private int getActionBarHeight() { | |
int actionBarHeight = getSupportActionBar().getHeight(); | |
if (actionBarHeight != 0) { | |
return actionBarHeight; | |
} | |
final TypedValue typedValue = new TypedValue(); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { | |
actionBarHeight = TypedValue.complexToDimensionPixelSize( | |
typedValue.data, getResources().getDisplayMetrics()); | |
} | |
} else { | |
// 使用android.support.v7.appcompat包做actionbar兼容的情况 | |
if (getTheme().resolveAttribute( | |
android.support.v7.appcompat.R.attr.actionBarSize, | |
typedValue, true)) { | |
actionBarHeight = TypedValue.complexToDimensionPixelSize( | |
typedValue.data, getResources().getDisplayMetrics()); | |
} | |
} | |
return actionBarHeight; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment