Android跳转新Activity后Splash Screen仍显示的问题求助
Hey there! Let's work through why your splash screen is sticking around and covering your new Activity—this is a super common pitfall for Android beginners, so don't worry, we'll get it sorted. Since you followed the "Splash Screen right way" guide, here are the most likely issues to check:
Double-check your Activity themes in AndroidManifest.xml
It's easy to accidentally apply the splash screen theme to your main Activity by mistake. Open yourAndroidManifest.xmland make sure:- Your Splash Activity uses the dedicated splash theme (e.g.,
@style/SplashTheme) - Your main Activity uses your app's regular theme (e.g.,
@style/AppTheme) instead of the splash one.
Example correct configuration:
<activity android:name=".SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:theme="@style/AppTheme" /> <!-- No splash theme here! -->- Your Splash Activity uses the dedicated splash theme (e.g.,
Ensure your Splash Activity calls
finish()after navigating
If you forget to finish the Splash Activity when launching your main Activity, it'll stay in the task stack and its background might still show through. Make sure your Splash Activity's navigation code includesfinish():Example in Kotlin:
class SplashActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // No need for setContentView—your splash theme handles the background Handler(Looper.getMainLooper()).postDelayed({ val intent = Intent(this, MainActivity::class.java) startActivity(intent) finish() // Critical: closes the Splash Activity }, 1000) } }Verify your splash theme is only for the splash screen
Your splash theme should only define thewindowBackgroundfor the splash screen, and your main app theme should override this with a normal background. Check yourstyles.xml:Splash theme:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/your_splash_drawable</item> </style>Main app theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:windowBackground">@color/white</item> <!-- Your other theme customizations --> </style>Clean and rebuild your project
Sometimes Android Studio's build cache can cause old theme settings to stick around. Go toBuild > Clean Project, thenBuild > Rebuild Projectto rule out caching issues.
If none of these fix it, feel free to share your AndroidManifest.xml and styles.xml code snippets—we can dig deeper!
内容的提问来源于stack exchange,提问作者Nguyen Hoang Vu

