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.
<!-- 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.
// 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.
<!-- 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.
“`