새소식

mobile/🦖 Android

[5분 내로] Kotlin splash 쉽게 구현하기

  • -
728x90

 

안녕하세요. 팀드모네입니다.

오늘은 Kotlin splash 구현하는 방법에 대해서 안내드립니다.

많은 사람들이 착각하는 것 같아 직접 포스팅합니다.

 

1. activity 생성

아래의 코드를 참고하여 res > layout 폴더에 activity_splash_screen.xml을 생성합니다.

</RelativeLayout>
        android:orientation="vertical"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="All In One"
            android:padding="10dp"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/black"/>
    </LinearLayout>

</RelativeLayout>

 

2. 스플래시 이미지 넣기

res > drawable 폴더에 splash.png 이미지를 넣어주세요

splash.png가 뭐냐면 스플래시 화면에서 띄울 이미지입니다.

 

3. color.xml 수정

res > values > color.xml에 아래의 코드를 기술해주세요

* color.xml의 디렉터리(파일 위치)는 당신의 개발 환경에 따라 조금씩 다를 수 있습니다.

<color name="windowBackground">#FFFFFFFF</color>

 

4. SplashScreenActivity 생성

SplashScreenActivity 코틀린 클래스 하나 생성하셔서 아래의 코드를 기입합니다.

class SplashScreenActivity : AppCompatActivity() {
    // After 3000 mileSeconds / 3 seconds your next activity will display.
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_screen)
        loadSplashScreen()
    }

    private fun loadSplashScreen(){
        Handler().postDelayed({
            // You can declare your desire activity here to open after finishing splash screen. Like MainActivity
            val intent = Intent(this,MainActivity::class.java)
            startActivity(intent)
            finish()
        }, 3000)
    }
}

 

5. manifest 수정

AndroidManifest.xml에 SplashScreenActivity를 기술해주세요.

* 아래의 코드를 참고하시면 감이 오실 것입니다.

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

    <uses-permission android:name="android.permission.INTERNET" />
    <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.Kotlin4javascriptinterface" >
        <activity android:name="io.cordova.seoulfilter.SplashScreenActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="io.cordova.seoulfilter.MainActivity" ></activity>

    </application>

</manifest>

 

끝! 작업이 잘 되셨기를 기원합니다 :)

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.