3

更新
私の電話にロック画面がある場合、この問題は発生しません

を使用して"androidx.core:core-splashscreen:1.0.0-alpha01"います。SplashScreen は適切に表示されます (白い背景に ic_launcher アイコンが表示されます) が、問題があります。
SplashScreen が表示された後、電源ボタンを押し (電話画面がオフ)、もう一度電源ボタンを押します (電話画面がオンになり、ステータス バーが表示されます) が、SplashScreen に黒い画面が表示されます。ここに私のデモコードがあります

themes.xml

<style name="Theme.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/white</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_background</item>
    <item name="postSplashScreenTheme">@style/Theme.AndroidSplashScreen12</item>
</style>

<style name="Theme.AndroidSplashScreen12" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <item name="colorPrimary">@color/purple_500</item>
    <item name="colorPrimaryVariant">@color/purple_700</item>
    <item name="colorOnPrimary">@color/white</item>
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_700</item>
    <item name="colorOnSecondary">@color/black</item>
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>

Androidマニフェスト

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AndroidSplashScreen12">

    <activity android:name=".SplashActivity"
        android:exported="true"
        android:theme="@style/Theme.MySplash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

スプラッシュ アクティビティ

class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val splashScreen = installSplashScreen()
        setContentView(R.layout.activity_splash)

        val content: View = findViewById(android.R.id.content)
        content.viewTreeObserver.addOnPreDrawListener { false } // keep SplashScreen display until move to MainActivity
 
        // I will do some long operator here then move to MainActivity
    }
}
4

1 に答える 1