[AI 앱 개발] v2v: value to value (Android Studio - Splash 화면 만들기)

danbibibi·2022년 8월 8일
0

Android Studio - Splash(Intro) 화면 만들기


  1. activity_splash.xml 파일을 만들고 다음과 같이 이미지를 넣어 준다. (res > drawable > intro 이미지 파일을 넣어놓고!)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/intro">
    </ImageView>
</LinearLayout>
  1. SplashActivity.java 파일을 만들고 다음과 같이 activity_splash화면을 보여준 후 Handler를 이용하여 activity_main.xml로 넘어가는 코드를 작성한다!
package com.skt.v2v;

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

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {

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

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 3000); // 3초 후 MainActivity
    }

    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }
}
  1. AndroidManifest.xml파일에서 기존 .MainActivity.SplashActivity로 수정해준다.

그리고 아래와 같이 MainActivity java 파일이 있음을 명시해준다. (미작성 시 앱이 튕긴다.)

<activity android:name=".MainActivity"/>
  1. 최종적으로 아래와 같이 Splash(Intro) 화면이 3초 뜨고 메인으로 넘어간다.

  1. Android Studio Project GitHub 연동
profile
블로그 이전) https://danbibibi.tistory.com

0개의 댓글