AI

안드로이드 일기장 및 가계부 만들기(java)-1.첫화면 splash만들기

다욤욤 2023. 8. 24. 14:36

앱 첫 실행시 보여지는 화면(splash)만들기

 

 

 

-띄우고자 하는 화면 만들기(res-layout)

[R.layout.activity_splash]

<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"
    android:orientation="vertical"
    tools:context=".SplashActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAlignBottom="true"
        android:scaleType="centerCrop"
        android:src="@drawable/splash" />

</LinearLayout>

 

 

-화면 띄우기

[SplashActivity]

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();    //액션바 숨기기
        }
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_splash);  //띄우고자 하는 화면 띄우기

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
            //splash 화면이 끝난뒤 연결해줄 class intent로 연결하기
                Intent intent=new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent);  
                finish();
            }
        },3000);
    }
    protected void onPause(){
        super.onPause();
        finish();
    }
}

 

-Manifest에 추가하기

    <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>