Android

代码获取statusbar的默认高度

2017-11-10  本文已影响0人  超威蓝猫l
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;
}
上一篇下一篇

猜你喜欢

热点阅读