美文网首页Android
代码获取statusbar的默认高度

代码获取statusbar的默认高度

作者: 超威蓝猫l | 来源:发表于2017-11-10 15:32 被阅读0次
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的默认高度

    本文链接:https://www.haomeiwen.com/subject/dfibmxtx.html