To avoid the appearance of an empty window before the splash screen
Add the style to the styles.xml
1 2 3 4 5
| <style name="SplashTheme" parent="Theme.AppCompat"> <item name="windowNoTitle">true</item> <item name="android:windowDisablePreview">true</item> <item name="android:windowBackground">@drawable/splash_screen</item> </style>
|
Add the style to the SplashActivity in AndroidManifest.xml
1 2 3 4 5 6 7 8
| <activity android:name=".activity.SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
|
Sample SplashActivity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| class SplashActivity : AppCompatActivity() {
var handler: Handler?=null lateinit var runnable: Runnable override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash)
val intent = getIntent() if (!isTaskRoot() && intent != null && intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_MAIN) ) { finish() return }
window.navigationBarColor = ContextCompat.getColor(this, R.color.splash_bottom) window.statusBarColor = ContextCompat.getColor(this, R.color.main_red)
handler = Handler(mainLooper) runnable = Runnable{ val mIntent = Intent(this@SplashActivity, MainActivity::class.java) startActivity(mIntent) finish() handler = null } handler?.postDelayed(runnable, 1000) } }
|