먼저 Activity를 만들어 준다. 

package com.example.ondroid; import android.content.Intent; import android.os.Bundle; import android.widget.ImageView; import androidx.appcompat.app.AppCompatActivity; public class LoadingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(getApplicationContext(),MainActivity.class); startActivity(intent); finish(); } }


인텐트로 넘어가게 한 후 이 화면은 초기에만 나타나게 할 것이므로 finish()를 사용하여 Activity를 없애준다.


그리고 AndroidManifest.xml 에 아래와 같이 등록 하여준다. androi:theme="@style/SplashTheme" 를 넣었으면 style 에 SplashTheme 태크를 넣어줘야한다.


<activity android:name=".LoadingActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>


아래는 src/main/res/values/styles.xml 에 등록하여준다.<style> 태그이므로 기존의 태그가 서로 겹치지 않게 해야한다.


<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/splash_background</item> </style>


위의 splash_background는 drawable폴더에 만들어준다.

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/splash_base"></item> <item android:top="210dp"> <bitmap android:src="@drawable/jamanchulogi" android:gravity="top"/> </item> </layer-list>


그리고 splash_base라는 xml을 drawable 폴더에 둬서 배경색으로 이용할 수 있다.

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#F4FFFF" android:centerColor="#F4FFFF" android:endColor="#F4FFFF" android:angle="90" android:centerY="0.5" /> <corners android:radius="0dp"/> </shape>



+ Recent posts