欢迎来到天天文库
浏览记录
ID:49619677
大小:134.00 KB
页数:29页
时间:2020-03-02
《android获取状态栏高度.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、android获取状态栏高度公司项目中使用了popWindow,并且需求指明了popWindow必须是和Activity类似的全屏模式,并且从页面底部弹出!当popWindow所有设计完毕后,从底部弹出popWindow,发现设置在popWindow的上的titlebar一部分被压入状态栏的底部了,也就是说全屏是全屏了,但是超过了应有的部分!解决方案:为了达到良好的兼容性,我们可以如下变现代码/***用于获取状态栏的高度。**@return返回状态栏高度的像素值。*/privateintgetSta
2、tusBarHeight(){intstatusBarHeight=0;try{Class>c=Class.forName("com.android.internal.R$dimen");Objecto=c.newInstance();Fieldfield=c.getField("status_bar_height");intx=(Integer)field.get(o);statusBarHeight=getResources().getDimensionPixelSize(x);}catch
3、(Exceptione){e.printStackTrace();Rectframe=newRect();getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);statusBarHeight=frame.top;}returnstatusBarHeight;}还可以使用Resource对象获取(推荐这种方式)privateintgetStatusBarHeight(){intresult=0;intresourceId=getR
4、esources().getIdentifier("status_bar_height","dimen","android");if(resourceId>0){result=res.getDimensionPixelSize(resourceId);}returnresult;}-----------------------------------2015-01-29更新--------------------------------------公司有测试人员发现,FlymeOS4.x/Andro
5、id4.4.4出现了问题,让人一头雾水,因此,这里把问题再次改正一下,目前Android4.4.4的系统不多,只检测到魅族的FlymeOS4.x有问题,所以对FlymeOS着重处理一下。手写判断是否是FlymeOsS4.x.xprivatebooleanisFlymeOs4x(){StringsysVersion=android.os.Build.VERSION.RELEASE;if("4.4.4".equals(sysVersion)){StringsysIncrement=android.os.
6、Build.VERSION.INCREMENTAL;StringdisplayId=android.os.Build.DISPLAY;if(!TextUtils.isEmpty(sysIncrement)){returnsysIncrement.contains("Flyme_OS_4");}else{returndisplayId.contains("FlymeOS4");}}returnfalse;}然后PopWindow改为intstatusBarHeight=getStatusBarHeig
7、ht();if(isFlymeOs4x()){searchFlightListWindow.setHeight(screenMetrics.heightPixels-statusBarHeight*2);//至于这里为什么乘以2,我只能说,除了鬼鬼们,只有魅族自己知道,我是发现获得的StatusBarHeight偏小,所以乘以2,实践检验是正确的,但也很无语searchFlightListWindow.showAtLocation(findViewById(R.id.main),Gravity.BO
8、TTOM,0,0);}else{searchFlightListWindow.setHeight(screenMetrics.heightPixels-statusBarHeight);searchFlightListWindow.showAtLocation(findViewById(R.id.main),Gravity.BOTTOM,0,0);}----------------------------ViewcontentView=getWindow().getD
此文档下载收益归作者所有