Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何添加闪屏_Java_Android_Icons_Google Play Services_Splash Screen - Fatal编程技术网

Java 如何添加闪屏

Java 如何添加闪屏,java,android,icons,google-play-services,splash-screen,Java,Android,Icons,Google Play Services,Splash Screen,我是java的新WBIE,我想在代码中添加闪屏。因此,我创建了一个名为splash.XML的布局XML: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" a

我是java的新WBIE,我想在代码中添加闪屏。因此,我创建了一个名为splash.XML的布局XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash" >

</RelativeLayout>
但它不工作,当我运行应用程序时,我在设备上发现两个应用程序图标

你能帮我吗


提前谢谢你

您可能必须在yout manifest.xml中进行如下意图筛选:

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

编辑它并仅为启动活动设置意图过滤器


<activity
    android:name=".Splash"
 >     
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />>     
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
< /activity>
>
这是androidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/application_name"
    android:logo="@drawable/ic_launcher"
    android:theme="@style/Theme.Easyrambooster" >
    <activity
        android:name="com.test.test.MainActivity"
        android:label="@string/application_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <service android:name="com.test.test.QuickBoosterService" >
    </service>

        <activity
        android:name="com.test.test.Splash">
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name="com.google.android.gms.ads.AdActivity"


像这样声明您的清单

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <!-- Splash screen -->
    <activity
        android:name=".SplashScreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <!-- Main activity -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>
</application>

给我看看你的清单文件代码你可能有两个与和相关的活动。Hoewever,只有你的splachScreen应该包含那些你犯错误的意图。。。。。像@Nitesh Pareek Answer一样检查我的最佳简单解决方案:从清单中的.main活动定义中删除这一行谢谢大家的回答。。问题已解决谢谢你的回答!检查我的最佳简易解决方案:
</manifest>
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <!-- Splash screen -->
    <activity
        android:name=".SplashScreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <!-- Main activity -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>
</application>
public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @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);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}