解决android 显示内容被底部导航栏遮挡的问题
描述:
由于产品需求,要求含有EditText的界面全屏显示,最好的解决方式是使用AndroidBug5497Workaround.assistActivity(this)
的方式来解决,但是华为和魅族手机系统自带的有底部导航栏,会造成一些布局被遮挡。
解决方案:在values-21的style.xml中添加android:windowDrawsSystemBarBackgrounds”并将值设置为false,方式如下
在style引用的主题里面加入android:windowDrawsSystemBarBackgrounds”并将值设置为false,会自动提醒点击alt+Enter会新建values-21的文件夹并生成styles.xml的文件。
也可以自己忽略的,直接新建values-21的文件夹然后新建一个styles.xml的文件,将主题里面的内容复制到styles.xml里面然后加上加入android:windowDrawsSystemBarBackgrounds”并将值设置为false即可解决。
例外:附上(网上找到的)
publicclassAndroidBug5497Workaround{ //Formoreinformation,seehttps://code.google.com/p/android/issues/detail?id=5497 //Tousethisclass,simplyinvokeassistActivity()onanActivitythatalreadyhasitscontent viewset. publicstaticvoidassistActivity(Activityactivity){ newAndroidBug5497Workaround(activity); } privateActivityactivity; privateViewmChildOfContent; privateintusableHeightPrevious; privateFrameLayout.LayoutParamsframeLayoutParams; privateAndroidBug5497Workaround(Activityactivity){ this.activity=activity; FrameLayoutcontent=(FrameLayout)activity.findViewById(android.R.id.content); mChildOfContent=content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){ publicvoidonGlobalLayout(){ possiblyResizeChildOfContent(); } }); frameLayoutParams=(FrameLayout.LayoutParams)mChildOfContent.getLayoutParams(); } privatevoidpossiblyResizeChildOfContent(){ intusableHeightNow=computeUsableHeight(); LogUtils.e("possiblyResizeChildOfContent","usableHeightNow:"+usableHeightNow); LogUtils.e("possiblyResizeChildOfContent","usableHeightPrevious:"+usableHeightPrevious); if(usableHeightNow!=usableHeightPrevious){ intusableHeightSansKeyboard=mChildOfContent.getRootView().getHeight(); //这个判断是为了解决19之前的版本不支持沉浸式状态栏导致布局显示不完全的问题 if(Build.VERSION.SDK_INT(usableHeightSansKeyboard/4)){ //keyboardprobablyjustbecamevisible frameLayoutParams.height=usableHeightSansKeyboard-heightDifference; }else{ //keyboardprobablyjustbecamehidden frameLayoutParams.height=usableHeightSansKeyboard; } mChildOfContent.requestLayout(); usableHeightPrevious=usableHeightNow; } } privateintcomputeUsableHeight(){ Rectframe=newRect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); intstatusBarHeight=frame.top; Rectr=newRect(); mChildOfContent.getWindowVisibleDisplayFrame(r); //这个判断是为了解决19之后的版本在弹出软键盘时,键盘和推上去的布局(adjustResize)之间有黑色区域 的问题 if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT){ return(r.bottom-r.top)+statusBarHeight; } return(r.bottom-r.top); } }
以上这篇解决android显示内容被底部导航栏遮挡的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。