안드로이드 인트로

1. 레이아웃 activity_intro.xml 추가


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="인트로" />

</LinearLayout>



2. 자바 IntroActivity 추가



package com.fractalwrench.androidbootstrap.sample;

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

/**
* Created by chickenNcola on 2017. 6. 25..
*/

public class IntroActivity extends Activity {
Handler handler;//핸들러 선언

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
handler= new Handler();
handler.postDelayed(mrun, 2000); // 시간 2초 딜레이
}

Runnable mrun = new Runnable(){
@Override
public void run(){
Intent HomeActivity = new Intent(IntroActivity.this, HomeActivity.class); //인텐트 생성(현 액티비티, 새로 실행할 액티비티)
startActivity(HomeActivity);
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
//overridePendingTransition : 서서히 사라지는 효과
}
};
//인트로 중에 뒤로가기를 누를 경우 핸들러를 끊어버려 아무일 없게 만드는 부분
//미 설정시 인트로 중 뒤로가기를 누르면 인트로 후에 홈화면이 나옴.
@Override
public void onBackPressed(){
super.onBackPressed();
handler.removeCallbacks(mrun);
}
}


3.  manifasts 파일에 코드 추가


<!-- 인트로 -->
<activity
android:name=".IntroActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


+ Recent posts