如何添加启动画面

时间:2016-07-08 12:23:55

标签: java android icons google-play-services splash-screen

我是java的新手,我想在代码中添加启动画面。所以我创建了一个名为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>

我创建了一个名为splash.java的java classe:

package com.test.test;


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

import com.test.test.R;


public class Splash extends Activity {

private boolean backbtnPress;
private static final int SPLASH_DURATION = 3000;
private Handler myHandler;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getActionBar().hide();

    setContentView(R.layout.splash);

    myHandler = new Handler();
    myHandler.postDelayed(new Runnable() {

        @Override
        public void run() {
            finish();

            if(!backbtnPress)
            {
                Intent intent = new Intent(Splash.this,MainActivity.class);
                Splash.this.startActivity(intent);
            }

        }
    }, SPLASH_DURATION);

}

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub

    backbtnPress = true;
    super.onBackPressed();
}
}

但它不起作用,当我运行应用程序时,我在设备上找到两个应用程序图标。

你可以帮我吗

提前谢谢!

4 个答案:

答案 0 :(得分:1)

可能你必须在你的manifest.xml中过滤这样的过滤器:

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

编辑它并为泼水活动设置意图过滤器

答案 1 :(得分:1)

宣布你的清单

val cookieNames = request.cookies.map{cookie =>
cookie.name
}

您的splashActivity代码就是这样的工作

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

这里是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"

机器人:configChanges =&#34;键盘| keyboardHidden |取向|屏幕布置| uiMode |屏幕尺寸| smallestScreenSize&#34; /&GT;     

</manifest>