最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Custom Splash Screen - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

If 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
        }
    }
}

发布评论

评论列表(0)

  1. 暂无评论