Android 如何在应用程序启动前放置图片?
我正在尝试在我的应用程序中添加图片,但不确定如何添加 我需要一个新的活动吗?如果是这样,该活动将如何理解何时停止并转到真正的程序Android 如何在应用程序启动前放置图片?,android,splash-screen,Android,Splash Screen,我正在尝试在我的应用程序中添加图片,但不确定如何添加 我需要一个新的活动吗?如果是这样,该活动将如何理解何时停止并转到真正的程序 澄清一下我想做什么:当你打开任何应用程序时,我可能认为他们会拥有我所说的东西。例如,Youtube应用程序打开时,在打开真正的应用程序之前,会有一个屏幕显示Youtube的徽标。我想这个屏幕大约需要3到5秒 它称为闪屏 您应该创建具有计时器的新活动。1-2秒后,它启动您的主要活动 按照下面的SAI使用飞溅活动。下面是一个例子: public class SplashA
澄清一下我想做什么:当你打开任何应用程序时,我可能认为他们会拥有我所说的东西。例如,Youtube应用程序打开时,在打开真正的应用程序之前,会有一个屏幕显示Youtube的徽标。我想这个屏幕大约需要3到5秒 它称为闪屏 您应该创建具有计时器的新活动。1-2秒后,它启动您的主要活动
按照下面的SAI使用飞溅活动。下面是一个例子:
public class SplashActivity extends Activity {
private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 2; // Time in seconds to show the picture
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
setContentView(R.layout.splash_screen); //your layout with the picture
// Start timer and launch main activity
IntentLauncher launcher = new IntentLauncher();
launcher.start();
}
private class IntentLauncher extends Thread {
@Override
/**
* Sleep for some time and than start new activity.
*/
public void run() {
try {
// Sleeping
Thread.sleep(SLEEP_TIME*1000);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
// Start main activity
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
}}
别忘了添加到清单中
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
你在问什么?如何在SplashScreen中显示图像,稍等片刻,然后启动MainActivity?可能的复制甚至比使用计时器更好,您可以使用AsyncTask完成长时间操作,然后完成SplashScreen并在其onPostExecute()