I want to create a splash activity

Asked 1 years ago, Updated 1 years ago, 86 views

I wanted to make the app look more fancy, so I was thinking about putting in a loading screen or something like that. How can I make a loading screen?

android splash-screen

2022-09-22 15:10

1 Answers

Creates a layout for Splash Activity.

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical" android:layout_width="fill_parent"
          android:layout_height="fill_parent">

          <ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content"
                  android:layout_height="fill_parent"
                  android:src="@drawable/splash"
                  android:layout_gravity="center"/>

          <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Hello World, splash"/>

  </LinearLayout>

And it creates Splash Activity.

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class Splash extends Activity {

    /** Time (in milliseconds) when the loading screen is up **/
    private final int SPLASH_DISPLAY_LENGTH = 1000;

    /** It is called when an activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.splashscreen);

        /* After SPLASH_DISPLAY_LENGTH, the menu activity is executed and terminated.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                /* Execute the menu activity and kill the loading screen.*/
                Intent mainIntent = new Intent(Splash.this,Menu.class);
                Splash.this.startActivity(mainIntent);
                Splash.this.finish();
            }
        }, }, SPLASH_DISPLAY_LENGTH);
    }
}

And go to the Android manifest file and start the activity Switch to Splash.


2022-09-22 15:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.