Skip to content

Instantly share code, notes, and snippets.

@JetXing
Created April 15, 2015 06:28
Show Gist options
  • Save JetXing/664a7f54c437b44ab73a to your computer and use it in GitHub Desktop.
Save JetXing/664a7f54c437b44ab73a to your computer and use it in GitHub Desktop.
get the height of actionBar
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