一、刘海屏适配可 参考对应手机官方文档
小米:dev.mi.com/console/doc/detail?pld=1160
oppo、vivo:open.oppomobile.com/wiki/doc#id=10159
在application中插入
<!-- OPPO -->
<meta-data
android:name="android.max_aspect"
android:value="2.2" /> <!-- 小米适配 -->
<meta-data
android:name="notch.config"
android:value="portrait|landscape" /> <!-- 允许绘制到华为刘海屏机型的刘海区域 -->
<meta-data
android:name="android.notch_support"
android:value="true" />
二、沉浸式状态栏
在引用的基类Activity中引用工具类,//沉浸式状态栏实现 SystemUI.fixSystemUI(this);
public class SystemUI {
public static void fixSystemUI(Activity mActivity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//获取最顶层的View
mActivity.getWindow().getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
mActivity.getWindow().setStatusBarColor(Color.TRANSPARENT);
}
}
}
三、 启动首页出现白屏
导致原因
theme用的是Theme.AppCompat.Light.NoActionBar:
<application
android:name=".application.MyApplication"
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:replace="icon, label, theme">
解决办法
添加一个新的style:
<activity
android:name=".activity.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/styleSplash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
style中windowIsTranslucent属性设置为true,背景透明:
<style name="styleSplash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>