首页 > 移动平台 > 详细

Android 获取 屏幕状态栏高度和标题栏高度 避免出现0的情况

时间:2015-08-18 12:24:12      阅读:225      评论:0      收藏:0      [点我收藏+]
@Override  
    public void onWindowFocusChanged(boolean hasFocus) {  
        super.onWindowFocusChanged(hasFocus);  
  
        Rect frame = new Rect();  
        getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
        int statusBarHeight = frame.top;  
        // 获取标题栏高度  
        Window window = getWindow();  
        int contentViewTop = getWindow()  
                .findViewById(Window.ID_ANDROID_CONTENT).getTop();  
        // statusBarHeight是上面所求的状态栏的高度  
        titleBarHeight = contentViewTop - statusBarHeight;  
  
        Log.i("test", "statusBarHeight=" + statusBarHeight + " contentViewTop="  
                + contentViewTop + " titleBarHeight=" + titleBarHeight);  
    }




Android 获取 屏幕状态栏高度和标题栏高度 避免出现0的情况

原文:http://my.oschina.net/sfshine/blog/493847

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!