未显示启动画面

时间:2013-04-01 13:32:45

标签: android android-layout android-intent

我在我的活动Splash中有这个代码。但是,当我启动我的应用程序时,问题就出现了。什么可能是“错误的步骤”在这里,我该怎么做才能让它排序?

public class Splash extends Activity {
    Handler handler;
    private long timeDelay = 2500;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        final Intent i = new Intent(this, Quotes.class);
        handler = new Handler(); 
        handler.postDelayed(new Runnable() { 
             public void run() { 
                 startActivity(i); 
                 finish();
             } 
        }, timeDelay); 
    }      


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.splash, menu);
        return true;
    }

}

4 个答案:

答案 0 :(得分:2)

在应用程序启动时将Splash活动设置为启动活动。在清单中添加以下代码。

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

答案 1 :(得分:0)

在清单

中设置启动画面活动
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="Packagename"
        android:versionCode="1"
        android:versionName="1.0" >

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

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

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

       </activity>

</application>

如果您的软件包当前使用此android:name =“。SplashActivity” 否则把android:name =“Package name.SplashActivity”

答案 2 :(得分:0)

公共类SplashActivity扩展了Activity {

private static final int SPALSH_TIME = 5000;// 5 Seconds

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);        

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {

            Intent intent = new Intent(SplashActivity.this,
                    MainTabActivity.class);
            startActivity(intent);
            SplashActivity.this.finish();

        }
    }, SPALSH_TIME);
}

@Override
public void onBackPressed() {
    SplashActivity.this.finish();
    super.onBackPressed();
}

}

答案 3 :(得分:0)

android:launchMode =“ singleTop”

android:theme =“ @ style / SplashTheme”

 <application
            android:name=".MainApplication"
            android:label="@string/app_name"
            android:icon="@mipmap/logo"
            android:allowBackup="false"
            android:theme="@style/SplashTheme">

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

</application>

styles.xml

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
    </style>

background_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
            android:drawable="@color/white"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/background_768_1024"/>
    </item>

</layer-list>