我在启动时在清单 android 文件中放入什么代码才能显示启动画面?

ERJ*_*JAN 0 android splash-screen main-activity

我已经在 SO 上查找了类似的帖子。我添加了 splash.java 类, splash_layout.xml 文件,

我有 2 个应用程序图标出现在桌面模拟器上,并且有飞溅,但 2 个图标不好 我怀疑它是关于清单的,我在那里放什么作为 android.MAIN、android.DEFAULT?

这是我的 android manifest.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kaban.it_ebooksinfomobile" >

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/Theme.Book">


    <something must be here for splash screen before MainActivity...>

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

这是飞溅的java文件:

package com.example.kaban.it_ebooksinfomobile;

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

public class SplashScreen extends Activity {


    private final int SPLASH_DISPLAY_LENGTH = 1000;
    private static boolean splashLoaded = false;


    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        if(!splashLoaded){
            setContentView(R.layout.splashscreen);
            splashLoaded = true ;

        /* 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. */
                    startActivity(new Intent(SplashScreen.this, MainActivity.class));
                    finish();
                }
            }, SPLASH_DISPLAY_LENGTH);
        }
        else {
            Intent goToMainActivity = new Intent(SplashScreen.this, MainActivity.class);
            goToMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(goToMainActivity);
            finish();
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

但它仍然没有加载我的飞溅!它曾经加载过,但在虚拟模拟器桌面上有 2 个应用程序图标,这很愚蠢。我认为将我的 .SplashActivity 作为我的启动器是不对的,我已经这样做了:

<activity
            android:name=".HomeScreen"
            android:label="@string/app_name" >>     
        </activity>

        <activity
            android:name=".Splash"
            android:label="@string/title_activity_splash_screen" >>     
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />>     
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        < /activity>
Run Code Online (Sandbox Code Playgroud)

Pau*_*nko 5

尝试这个:

    <activity
        android:name=".SplashScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />                
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)