代码获取statusbar的默认高度

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;
}

你可能感兴趣的:(代码获取statusbar的默认高度)