admin管理员组文章数量:1415101
I want to make my own splash screen, but my icon is corrupted
I created my own theme and wrote it down there, as it says in the documentation, but I still couldn't do it.I tried changing the image and even tried to make it vector, but it still gets cut off in a circle
enter image description here
In the end I did it this way @SuppressLint("CustomSplashScreen") class SplashActivity : AppCompatActivity() { private lateinit var registrationUser: RegistrationUser
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
registrationUser = RegistrationUser(this)
Handler(Looper.getMainLooper()).postDelayed({
val savedPhone = registrationUser.getCachedPhoneNumber()
if (savedPhone != null){
registrationUser.getPhoneKey(savedPhone)
}else{
startActivity(Intent(this, RegistrationActivity::class.java))
}
}, 2500)
}
} and now I have this unnecessary screenenter image description here
How can I remove this screen or make it my own? P.s.
I changed the activity theme in the manifest as needed
I want to make my own splash screen, but my icon is corrupted
I created my own theme and wrote it down there, as it says in the documentation, but I still couldn't do it.I tried changing the image and even tried to make it vector, but it still gets cut off in a circle
enter image description here
In the end I did it this way @SuppressLint("CustomSplashScreen") class SplashActivity : AppCompatActivity() { private lateinit var registrationUser: RegistrationUser
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
registrationUser = RegistrationUser(this)
Handler(Looper.getMainLooper()).postDelayed({
val savedPhone = registrationUser.getCachedPhoneNumber()
if (savedPhone != null){
registrationUser.getPhoneKey(savedPhone)
}else{
startActivity(Intent(this, RegistrationActivity::class.java))
}
}, 2500)
}
} and now I have this unnecessary screenenter image description here
How can I remove this screen or make it my own? P.s.
I changed the activity theme in the manifest as needed
Share Improve this question asked Feb 23 at 13:25 ДмитрийДмитрий 1 1- Please don't leave the default text “enter image description here”, always change it to some image description. Please don't post textual information in the form of pictures. – Sergey A Kryukov Commented Feb 24 at 2:14
1 Answer
Reset to default 0If your emulator runs Android 12 or higher, you can not remove the default system splash screen and use the Splash Screen API instead. Follow these steps:
Add the Splash Screen Library
Add the following dependency to your build.gradle file:
dependencies {
implementation("androidx.core:core-splashscreen:1.0.0")
}
create this style in theme.xml
<style name="Theme.YourApp.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/your_background_color</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
<item name="postSplashScreenTheme">@style/Theme.YourApp</item>
</style>
Check the correct splash screen logo dimensions here: https://developer.android/develop/ui/views/launch/splash-screen#dimensions
add your style in AndroidManifest.xml
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.YourApp.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Update MainActivity to control the splash screen visibility based on savedPhone:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
val registrationUser = RegistrationUser(this)
val savedPhone = registrationUser.getCachedPhoneNumber()
// Keep splash screen visible while checking login state
splashScreen.setKeepOnScreenCondition { savedPhone == null }
if (savedPhone != null) {
registrationUser.getPhoneKey(savedPhone)
} else {
startActivity(Intent(this, RegistrationActivity::class.java))
finish() // Close MainActivity so it doesn't stack
}
}
}
本文标签: androidCustom Splash ScreenStack Overflow
版权声明:本文标题:android - Custom Splash Screen - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745153574a2645032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论