六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 16|回复: 0

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

[复制链接]

升级  12%

410

主题

410

主题

410

主题

探花

Rank: 6Rank: 6

积分
1240
 楼主| 发表于 2013-2-3 10:30:11 | 显示全部楼层 |阅读模式
1.获取状态栏高度:

decorview是window中的最顶层view,可以从window中获取到decorview,然后decorview有个getwindowvisibledisplayframe方法可以获取到程序显示的区域,包括标题栏,但不包括状态栏。
于是,我们就可以算出状态栏的高度了。
rect frame =  new  rect();  getwindow().getdecorview().getwindowvisibledisplayframe(frame);  int  statusbarheight = frame.top;  
rect frame = new rect();  getwindow().getdecorview().getwindowvisibledisplayframe(frame);  int statusbarheight = frame.top;

2.获取标题栏高度:

getwindow().findviewbyid(window.id_android_content)这个方法获取到的view就是程序不包括标题栏的部分,然后就可以知道标题栏的高度了。
int  contenttop = getwindow().findviewbyid(window.id_android_content).gettop();  //statusbarheight是上面所求的状态栏的高度   int  titlebarheight = contenttop - statusbarheight  
int contenttop = getwindow().findviewbyid(window.id_android_content).gettop();  //statusbarheight是上面所求的状态栏的高度  int titlebarheight = contenttop - statusbarheight
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表