점진적 과부하 개발 블로그

Android Splash Screen 화면 구현 본문

Android/Java

Android Splash Screen 화면 구현

지용빡 2022. 6. 5. 23:29
반응형
Android Splash Screen 화면 구현 
SplashActivy 만들기

import androidx.appcompat.app.AppCompatActivity;

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

public class SplashActivity extends AppCompatActivity {

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

        Handler hd = new Handler();
        hd.postDelayed(new SplashHandler(), 3000);
    }

    private class SplashHandler implements  Runnable {
        @Override
        public void run() {
            startActivity(new Intent(getApplication(), MainActivity.class));
            SplashActivity.this.finish();
        }
    }
}
  • 소스 추가
    • 3초 머물다 MainActity로 넘어감
activity_splash.xml
  • Splash Screen 디자인 , 간단하게 텍스트 추가
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context=".SplashActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Splash Screen"
        android:textStyle="bold"
        android:textSize="50sp"
        android:textColor="@color/black"/>

</LinearLayout>
AndroidManifest.xml 수정 
  • SplashActivity가 먼저 불러올수 있게 Manifest 파일 수정
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SplashTest">
        <activity android:name=".MainActivity"></activity>
        <activity android:name=".SplashActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
실행화면
  • 성공 ! 

반응형

'Android > Java' 카테고리의 다른 글

Android 13주차 Graphic  (0) 2022.05.30
Android Toast & Snackbar  (0) 2022.04.19