1

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

4

1 に答える 1

3

アクティビティがランチャー アクティビティとして選択されていないようです。これを Android マニフェストに追加します。

        <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 アクティビティ タグからこの部分を削除します。

また、タイプミスがあるようです。MainActivity を起動する場合は、from を変更する必要があります。

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

  Intent mainIntent = new Intent(MainActivity.this,Menu.class);
于 2013-10-30T14:55:26.783 に答える