準備一張圖檔放在res⇒drawable-hdpi資料夾裡
1.AndroidManifest.xml
android:name="Your_package.SplashScreen"⇒⇒⇒⇒Your_package 你的package="xxx.xxxx.xxxxxx"
android:screenOrientation="portrait"⇒⇒⇒⇒landscape-橫屏,portrait-豎屏
action android:name="android.intent.action.MAIN"⇒⇒⇒⇒啟動點
category android:name="android.intent.category.LAUNCHER"⇒⇒⇒⇒啟動圖示
2.activity_splash.xml
在res⇒layout建立activity_splash.xml檔案
android:src="@drawable/load"⇒⇒⇒⇒load為圖檔名稱
3.SplashScreen.java
在跟MainActivity.java檔案同一個位置建立SplashScreen.java
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; public class SplashScreen extends Activity { // Splash screen timer private static int SPLASH_TIME_OUT = 3000; //開啟畫面時間(3秒) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); new Handler().postDelayed(new Runnable() { /* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / company */ @Override public void run() { // This method will be executed once the timer is over // Start your app main activity Intent i = new Intent(SplashScreen.this, MainActivity.class); //MainActivity為主要檔案名稱 startActivity(i); // close this activity finish(); } }, SPLASH_TIME_OUT); } }參考來源:http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
沒有留言 :
張貼留言