0

我的活动 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

4 回答 4

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>
于 2013-04-02T04:59:27.027 回答
0

在 mainfest 中设置启动画面活动

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

于 2013-04-02T05:47:18.537 回答
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();
}

}

于 2013-04-02T06:28:43.817 回答
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>

样式.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>
于 2019-10-03T09:48:45.350 回答