解决android 显示内容被底部导航栏遮挡的问题
作者:滕玉坤 时间:2021-08-05 10:10:55
描述:
由于产品需求,要求含有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即可解决。
例外:附上(网上找到的)
public class AndroidBug5497Workaround {
// For more information, see https://code.google.com/p/android/issues/detail?id=5497
// To use this class, simply invoke assistActivity() on an Activity that already has its content
view set.
public static void assistActivity (Activity activity) {
new AndroidBug5497Workaround(activity);
}
private Activity activity;
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private AndroidBug5497Workaround(Activity activity) {
this.activity = activity;
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new
ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
LogUtils.e("possiblyResizeChildOfContent","usableHeightNow:"+usableHeightNow);
LogUtils.e("possiblyResizeChildOfContent","usableHeightPrevious:"+usableHeightPrevious);
if (usableHeightNow != usableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
//这个判断是为了解决19之前的版本不支持沉浸式状态栏导致布局显示不完全的问题
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
usableHeightSansKeyboard -= statusBarHeight;
}
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
if (heightDifference > (usableHeightSansKeyboard/4)) {
// keyboard probably just became visible
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
} else {
// keyboard probably just became hidden
frameLayoutParams.height = usableHeightSansKeyboard;
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
Rect r = new Rect();
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);
}
}
来源:https://blog.csdn.net/tyk9999tyk/article/details/78457372
标签:android,导航栏,遮挡
0
投稿
猜你喜欢
深入理解C#中new、override、virtual关键字的区别
2021-08-29 05:42:37
教你使用java实现去除各种空格
2022-09-21 21:27:07
Java ClassLoader虚拟类实现代码热替换的示例代码
2022-06-25 03:08:52
MyBatis超详细讲解如何实现分页功能
2023-08-22 23:06:51
Flutter 图片开发核心技能快速掌握教程
2023-08-16 22:01:51
基于C语言string函数的详解
2023-06-28 05:33:25
Java实现选择排序
2021-06-30 16:53:55
java开发分布式服务框架Dubbo原理机制详解
2023-01-04 19:53:01
Kotlin协程launch原理详解
2023-05-19 09:36:01
Java中Set与List的关系与区别介绍
2023-03-17 08:01:07
使用Java操作TensorFlow的方法
2023-11-27 21:31:38
Spring MVC URL地址映射的示例代码
2022-12-09 19:53:33
Android实现H5与Native交互的两种方式
2023-01-01 05:35:42
c#中SqlTransaction——事务详解
2022-12-16 15:40:54
论Java Web应用中调优线程池的重要性
2023-06-13 04:56:27
详解Java动态字节码技术
2022-06-20 03:20:20
Java中常见的陷阱题及答案
2021-08-10 16:32:11
C# 9 新特性——record的相关总结
2022-01-25 07:33:35
理解java设计模式之建造者模式
2023-03-13 14:48:55
spring AOP定义AfterThrowing增加处理实例分析
2021-07-11 14:22:11