Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Create a Splash Screen in Android

Tiempo de lectura: 2 minutos

Create a splash screen ad in an Android application is a relatively simple process.

Here, I provide you with a step-by-step tutorial using the Kotlin programming language and the Android Studio development environment.

1. Create a new project in Android Studio:

Open Android Studio and select “New Project.” Complete the basic project setup.

2. Design the splash screen layout:

Open the file res/layout/activity_splash.xml and add a basic layout for the splash screen. You can customize it according to your needs.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!-- res/layout/activity_splash.xml -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
<!-- Add your logo or other design elements here -->
</RelativeLayout>
<!-- res/layout/activity_splash.xml --> <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary"> <!-- Add your logo or other design elements here --> </RelativeLayout>
<!-- res/layout/activity_splash.xml -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary">

    <!-- Add your logo or other design elements here -->

</RelativeLayout>

3. Create the Splash activity:

Create a new class called SplashActivity.kt and set it as the main activity in your AndroidManifest.xml file.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// src/main/java/com/your_package/SplashActivity.kt
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
// Add a timer to simulate loading
val splashTimer = object : Thread() {
override fun run() {
try {
sleep(3000) // Time in milliseconds
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
finish()
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
}
splashTimer.start()
}
}
// src/main/java/com/your_package/SplashActivity.kt import android.content.Intent import android.os.Bundle import androidx.appcompat.app.AppCompatActivity class SplashActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash) // Add a timer to simulate loading val splashTimer = object : Thread() { override fun run() { try { sleep(3000) // Time in milliseconds val intent = Intent(applicationContext, MainActivity::class.java) startActivity(intent) finish() } catch (e: InterruptedException) { e.printStackTrace() } } } splashTimer.start() } }
// src/main/java/com/your_package/SplashActivity.kt
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

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

        // Add a timer to simulate loading
        val splashTimer = object : Thread() {
            override fun run() {
                try {
                    sleep(3000) // Time in milliseconds
                    val intent = Intent(applicationContext, MainActivity::class.java)
                    startActivity(intent)
                    finish()
                } catch (e: InterruptedException) {
                    e.printStackTrace()
                }
            }
        }

        splashTimer.start()
    }
}

4. Set up the main activity:

Edit the main activity (MainActivity.kt) to be the next in your application flow.

5. Update the AndroidManifest.xml file:

Ensure that the SplashActivity activity is the first one to start.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!-- AndroidManifest.xml -->
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<!-- ... other configurations ... -->
</activity>
<!-- AndroidManifest.xml --> <activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"> <!-- ... other configurations ... --> </activity>
<!-- AndroidManifest.xml -->
<activity android:name=".SplashActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity android:name=".MainActivity">
    <!-- ... other configurations ... -->
</activity>

6. Add loading ads (optional):

If you want to display ads during loading, you can integrate ad libraries like Google’s AdMob. Follow the AdMob documentation for detailed instructions on how to integrate ads into your app.

Remember to add the necessary dependencies in your build.gradle file.
“`

0

Leave a Comment