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

来源:互联网 发布:蜂王浆胶囊 知乎 编辑:程序博客网 时间:2024/06/03 10:17
    int titleBarHeight;    @Override    public void onWindowFocusChanged(boolean hasFocus) {        super.onWindowFocusChanged(hasFocus);          Rect frame = new Rect();             getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);             int statusBarHeight = frame.top;             // 获取标题栏高度             int contentViewTop = getWindow()                     .findViewById(Window.ID_ANDROID_CONTENT).getTop();             // statusBarHeight是上面所求的状态栏的高度             titleBarHeight = contentViewTop - statusBarHeight;             Log.i("test", "statusBarHeight状态栏=" + statusBarHeight + " contentViewTop整个顶部的高度="                     + contentViewTop + " titleBarHeight标题栏=" + titleBarHeight);      }
0 0
原创粉丝点击