처음부터 차근차근

Splash 화면 만들기 본문

프로그래밍/Android

Splash 화면 만들기

_soyoung 2022. 6. 3. 13:50
반응형

Splash Screen

이미지나 로고, 현재 버전의 소프트웨어를 포함한 그래픽 요소를 보여주는 화면으로 보통 프로그램이 실행되고 있을 때 나오는 화면이다.

앱이 처음 실행될 때 나타난다.

 

 

만드는 방법

1. res / drawable 에 splash할 이미지 파일을 넣는다

 

 

2. res / values 에 style.xml 파일 새로 생성한

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    ...
    <!-- Customize your theme here. -->
    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash</item>
    </style>
</resources>

이런식으로 style을 추가한다.

 

 

3. MainActivity.java 있는 위치(java / 패키지명)에서  SplashActivity.java 새로 생성

SplashActivity.java

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(intent);
        finish();
    }
}

이로써 splash 화면이 끝나면 바로 메인화면으로 이동할 수 있다.

 

 

4. manifests / AndroidManifest.xml 수정

manifests 파일에 splash화면이 가장 먼저 실행되도록 수정해준다.
테마도 @style/SplashTheme로 수정해준다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fff">
    <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.Fff">
        <activity
            android:name=".MainActivity"
            android:exported="true">
        </activity>
        <activity
            android:name=".SplashActivity"
            android:exported="true"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

SplashActivity 액티비티를 추가해주고,

MainActivity 안에 있던 intent-filter을 SplashActivity로 안으로 옮겨주면 된다. 

 

 

결과

잘되는 것을 확인함

 

 

다른 방법(이게 더 쉬움)

1. res / drawable 에 splash할 이미지 파일을 넣는다

 

 

2. res / layout 아래에 splash_activity.xml 새로 생성

<?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"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/splash" >
    </ImageView>

</LinearLayout>

 

 

3. MainActivity.java 있는 위치(java / 패키지명)에서  SplashActivity.java 새로 생성

SplashActivity.java

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceStare) {
        super.onCreate(savedInstanceStare);
        setContentView(R.layout.splash_activity);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                startActivity(intent);
                finish();
            }
        },3000); // 3초 있다 메인액티비티로
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }
}

 

 

4. manifests / AndroidManifest.xml 수정

manifests 파일에 splash화면이 가장 먼저 실행되도록 수정해준다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fff">

    <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.Fff">
        <activity
            android:name=".MainActivity"
            android:exported="true">
        </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>

</manifest>

SplashActivity 액티비티를 추가해주고,

MainActivity 안에 있던 intent-filter을 SplashActivity로 안으로 옮겨준다.

 

 

결과

잘되는 것을 확인함

 

 

 

 

참고 : https://velog.io/@s2ilver8/Android-StudioSplash-%ED%99%94%EB%A9%B4-%EB%A7%8C%EB%93%A4%EA%B8%B0

 

[Android Studio]Splash 화면 만들기

Splash Screen이란? 이미지나 로고, 현재 버전의 소프트웨어를 포함한 그래픽 요소를 보여주는 화면으로 보통 프로그램이 실행되고 있을 때 나오는 화면이다. Splash Screen의 목적 안드로이드 앱을 시

velog.io

https://deumdroid.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%8A%A4%ED%8A%9C%EB%94%94%EC%98%A4-Intro%ED%99%94%EB%A9%B4-%EB%A7%8C%EB%93%A4%EA%B8%B0splash

 

안드로이드 스튜디오 Intro화면 만들기(splash)

안녕하세요 오늘은 원하는 사진이나 글로 메인 액티비티 시작 전 스플래쉬 화면을 만들어 보겠습니다. 스플래쉬 화면은 로딩 중이나 또는 앱 홍보(브랜드) 목적으로 많이 사용합니다. 일단 프로

deumdroid.tistory.com

 

반응형

'프로그래밍 > Android' 카테고리의 다른 글

고급 위젯과 프래그먼트  (0) 2022.06.13
안드로이드 그래픽  (0) 2022.05.30
RxJava  (0) 2022.05.08
Reactive programming(수정)  (1) 2022.04.22
팝업 메뉴  (1) 2022.04.19
Comments