들어가며
인트로 화면을 만들기 위해서는 다음의 3가지의 활동이 필요하다.
- 인트로 화면으로 보여줄 화면(intro.xml) 작성
- 인트로 화면을 띄워줄 소스파일(intro.java) 작성
- 매니페스트 파일에서 가장 처음 실행되는 액티비티를 인트로 액티비티로 설정
1. 새 프로젝트 만들기
먼저 새로운 프로젝트를 만들겠다. 이름은 Intro Test로 설정했다.
2. 새 액티비티 생성
인트로 화면으로 띄워줄 새로운 액티비티를 만들어본다.
app/java 폴더 밑에 패키지 이름으로 설정된 폴더를 우클릭하고
New - Activity - Empty Activity를 클릭하면 다음의 창이 뜬다.
이름으로 IntroActivity라고 입력후 Finish를 누르면 액티비티가 생성된다.
activity_intro.xml파일과 IntroActivity.java 파일이 만들어지는 것을 볼 수 있다.
3. activity_intro.xml 파일 수정
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="#202020"
tools:context=".IntroActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="200dp"
android:text="Macgyvering"
android:textColor="#EEDFDF"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
4. IntroActivity.java 파일 수정
package com.hopemoonstudio.introtest;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
public class IntroActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
},3000);
}
@Override
protected void onPause() {
super.onPause();
finish();
}
}
5. 매니페스트 파일에 등록
매티페스트 파일에 들어가면 이렇게 작성되어 있을 것이다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hopemoonstudio.introtest">
<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/AppTheme">
<activity android:name=".IntroActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
이는 메인 액티비티를 가장 먼저 실행하도록 되어있는 모습인데
인텐트 필터 태그를 전체 잘라내어 다음과 같이 인트로 액티비티 태그 안에 넣어준다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hopemoonstudio.introtest">
<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/AppTheme">
<activity android:name=".IntroActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"></activity>
</application>
</manifest>
결과
3초 뒤 메인화면이 뜨는 것을 확인할 수 있다.
'안드로이드 > 안드로이드 앱 개발' 카테고리의 다른 글
[Android] 안드로이드 스튜디오 설치 및 실행 방법 (0) | 2021.11.22 |
---|
댓글