SplashActivity的onCreate中
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
View decorView = window.getDecorView();
decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
return defaultInsets.replaceSystemWindowInsets(
defaultInsets.getSystemWindowInsetLeft(),
0,
defaultInsets.getSystemWindowInsetRight(),
defaultInsets.getSystemWindowInsetBottom());
}
});
ViewCompat.requestApplyInsets(decorView);
//将状态栏设成透明,如不想透明可设置其他颜色
window.setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent));
}
AndroidManifest.xml中application节点下添加
<!-- 全面屏 -->
<meta-data
android:name="android.max_aspect"
android:value="2.4" />
<!--适配华为(huawei)刘海屏-->
<meta-data
android:name="android.notch_support"
android:value="true"/>
<!--适配小米(xiaomi)刘海屏-->
<meta-data
android:name="notch.config"
android:value="portrait|landscape" />
<!-- vivo -->
<meta-data
android:name="android.vendor.full_screen"
android:value="true" />