アンドロイドスプラッシュ画面

アンドロイドのスプラッシュ画面は、アプリケーションが起動された際にユーザーに最初に表示される画面です。スプラッシュ画面は、ユーザーにとってアプリケーションとの初めての経験となるため、非常に重要な画面の一つです。スプラッシュ画面は、一部のデータを次の画面に取得する間、アプリケーションのロゴなどのアニメーションやイラストを表示するために使用されます。

アンドロイドのスプラッシュスクリーン

android splash screen
<intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

Androidのスプラッシュスクリーンのサンプルプロジェクトの構造

android splash screen example project structure

スプラッシュスクリーンのクラシカルなアプローチ

スプラッシュアクティビティ.java

package com.scdev.splashscreen;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed(new Runnable() {


            @Override
            public void run() {
                // This method will be executed once the timer is over
                Intent i = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }, 5000);
    }
}

通常、アプリケーションのスプラッシュ画面のレイアウトは以下のように作成します: activity_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:app="https://schemas.android.com/apk/res-auto"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    tools:context="com.scdev.splashscreen.SplashActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="72dp"
        android:layout_height="72dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@id/imageView" />

</android.support.constraint.ConstraintLayout>
android splash screen android studio classical approach

正しいアプローチを用いたAndroidスプラッシュ画面の例

スプラッシュアクティビティのレイアウトファイルを読み込むのに時間がかかるため、寒い冷たいスタートが表示されます。そのため、レイアウトを作成する代わりに、アプリケーションのテーマの力を使って初期レイアウトを作成します。アプリケーションのテーマはレイアウトが作成される前にインスタンス化されます。以下のように、アクティビティの背景とアイコンを含むdrawableをandroid:windowBackground属性に設定します。splash_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="https://schemas.android.com/apk/res/android">

    <item android:drawable="@android:color/black" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher" />
    </item>
</layer-list>

以下のスタイルを活動のテーマとして設定します。styles.xml

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_background</item>
    </style>

SplashActivity.javaファイルは、以下のようになるはずです。

package com.scdev.splashscreen;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        new Handler().postDelayed(new Runnable() {


            @Override
            public void run() {
                // This method will be executed once the timer is over
                Intent i = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }, 5000);
    }
}

android splash screen example android studio

Android スプラッシュスクリーンのサンプルプロジェクトをダウンロードしてください。

コメントを残す 0

Your email address will not be published. Required fields are marked *