public int getToolBarHeight() {
int[] attrs = new int[] {android.R.attr.actionBarSize};
TypedArray ta = getContext().obtainStyledAttributes(attrs);
int toolBarHeight = ta.getDimensionPixelSize(0, -1);
ta.recycle();
return toolBarHeight;
}
如果使用AppCompat包
public int getToolBarHeight() {
int[] attrs = new int[] {R.attr.actionBarSize};
TypedArray ta = getContext().obtainStyledAttributes(attrs);
int toolBarHeight = ta.getDimensionPixelSize(0, -1);
ta.recycle();
return toolBarHeight;
}