问题
1.如何适配解决全屏显示状态下,刘海屏,曲面屏等顶部显示不全的问题?
解决方法:在AndroidMainfest.xml文件之中添加下面的声明参数
该参数配置在< application >标签里面
<!--全面屏支持-->
<meta-data
android:name="android.max_aspect"
android:value="2.35" /> //ratio_float 被定义为是高除以宽.系统默认以16:9为例,未配置情况下默认为1.86 。 建议配置为2.2以上
<meta-data
android:name="notch.config"
android:value="portrait|landscape" />
<!-- 华为全面屏支持-->
<meta-data
android:name="android.notch_support"
android:value="true" />
2.配置了Maximum Aspect Ratio 后,但是底部的虚拟导航栏还是显示,该如何解决?
解决方法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
//去除全屏下的 虚拟导航栏
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
} else {
Window window = activity.getWindow();
WindowManager.LayoutParams attributes = window.getAttributes();
int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
attributes.flags |= flagTranslucentStatus;
window.setAttributes(attributes);
}
3.顶部状态栏和底部虚拟导航栏和布局内容重叠
解决方法:
在layout的根view之中添加下面属性即可
android:fitsSystemWindows="true"
评论区