模拟器一堆,有时候用别的测试才发现问题,这个是一个webview套的网页,在一些机型完全没感觉,但是有些机型显示的时候会把最下面的底部的导航栏挡住了H5的飘浮栏,因为它是固定在页面的最底部的,问题来了,我这个屏幕的尺寸为1440*2560的
DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metric); int width = metric.widthPixels; // 屏幕宽度(像素) int height = metric.heightPixels; // 屏幕高度(像素)所得到的高度却是2392!
Resources resources = getResources(); int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android"); //获取NavigationBar的高度 int height2 = resources.getDimensionPixelSize(resourceId); tLogD("NavigationBar的高度:" + height2 );这个高度是168!
一开始以为是这个168就是底部的导航栏的高度,
后来测试了一下,原来是顶层的导航栏。
底部导航栏的高度在上面的代码并没有去除,只是去除了顶层导航栏,而到了webview使用时,问题才出来了,底部导航栏会挡住刚好H5的底部飘浮栏。。。异常郁闷,还不一定每台机都会这样。。。
解决方法:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//A //导航栏 @ 底部 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);//B在所需要的activity中加入这段代码,使获取屏幕高宽时去除两个导航栏,再到xml中添加:android:fitsSystemWindows="true"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" >去除了actionbar,title,底部按键的空间后剩余的可用区域;这个属性设置为true,则忽略,false则不忽略
终于搞定。。。