一、劉海屏適配可 參考對應手機官方文檔
小米: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>