Android获取状态栏和标题栏的高度

来源:互联网 发布:excel数据汇总合并 编辑:程序博客网 时间:2024/05/29 04:14

获取状态栏的高度的方法如下:

    private int getStatusBarHeight(){    Rect rect = new Rect();    getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);    Log.d("yubo", "status bar height:" + rect.top);    return rect.top;    }

获取标题栏的高度的方法如下:

    private int getTitleBarHeight(){    int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();    Log.d("yubo", "title bar height:" + (contentTop - getStatusBarHeight()));    return contentTop - getStatusBarHeight();    }




0 0