2013-10-30 53 views
0

使用Android Studio我想在我的應用程序中加載啓動畫面,時間爲6秒,然後再打開遊戲活動。我同時提供了java代碼和xml,但是當我啓動設備時,啓動畫面不會出現。我不明白什麼是錯誤。 你能幫我`如何設置啓動畫面

這是我SplashScreenActivity.java

public class SplashScreenActivity extends Activity { 

private final int SPLASH_DISPLAY_LENGHT = 6000; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.splash); 

    /* New Handler to start the Menu-Activity 
    * and close this Splash-Screen after some seconds.*/ 
    new Handler().postDelayed(new Runnable(){ 
     @Override 
     public void run() { 
      /* Create an Intent that will start the Menu-Activity. */ 
      Intent mainIntent = new Intent(SplashScreenActivity.this,Menu.class); 
      SplashScreenActivity.this.startActivity(mainIntent); 
      SplashScreenActivity.this.finish(); 
     } 
    }, SPLASH_DISPLAY_LENGHT); 
} 

}

和文件的XML:

<RelativeLayout 
android:id="@+id/LinearLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:gravity="center" 
android:background="#ff000000"> 
<TextView android:id="@+id/TextView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="18sp" 
    android:textStyle="bold" 
    android:textColor="#fff" 
    android:text="LOADING..." 
    android:layout_marginTop="250dp" 
    android:layout_marginLeft="30dp"/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="500dp" 
    android:textColor="#ffffffff" 
    android:text="" 
    android:gravity="center"/> 

+0

檢查清單!這裏是一個教程如何創建一個Splash Activity - 最佳實踐:http://www.sherif.mobi/2012/09/how-to-create-splash-activity-best.html –

+4

我強烈建議不要使用Splashscreen,除非你正在做一些後臺處理。用戶往往會煩惱等待應用程序主屏幕。 – Si8

回答

2

好像你的活動ISN未被選爲啓動器活動。活動標籤內

 <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

所以它應該看起來像

<activity 
     android:name="your.package.SplashScreenActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

,並刪除這部分從您的MainActivity活動標籤: 添加到您的Android清單。

此外,它看起來像你有一個錯字。如果你想推出一個MainActivity,你應該 您從

Intent mainIntent = new Intent(SplashScreenActivity.this,Menu.class); 

改變

Intent mainIntent = new Intent(MainActivity.this,Menu.class);