Android 齐刘海适配

Android 齐刘海适配

1.基于现Android厂家逐渐开始在自家旗舰机上使用刘海屏,为了达到更好的全屏视觉体验,总结现流行厂商适配方式

2.不同厂商适配方案
华为:
在应用的AndroidManifest.xml中增加meta-data属性android.notch_support
<meta-data android:name=“android.notch_support” android:value=“true”/>

小米:
在应用的AndroidManifest.xml中增加meta-data属性 android:name=“notch.config”
<meta-data android:name=“notch.config” android:value=“portrait|landscape”/>
其中,value 的取值可以是以下4种:

  1. “none” 横竖屏都不绘制耳朵区
  2. “portrait” 竖屏绘制到耳朵区
  3. “landscape” 横屏绘制到耳朵区
  4. “portrait|landscape” 横竖屏都绘制到耳朵区

OPPO与VIVO:
在应用的AndroidManifest.xml中增加meta-data属性 android:name=“android.max_aspect”
<meta-data android:name=“android.max_aspect” android:value=“ratio_float” />

设置好注册文件后在对应适配的activity中做如下代码设置:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
int flag = 0x00000100 | 0x00000200 | 0x00000400;
try {
Method method = Window.class.getMethod(“addExtraFlags”,
int.class);
method.invoke(getWindow(), flag);
} catch (Exception e) {
}
注:1.小米配置 0x00000100:开启配置 0x00000200:竖屏配置 0x00000400:横屏配置
2.除华为外其它适配需手动开启系统全屏权限
3.效果图

Android 齐刘海适配