如何在应用程序启动前放一张图片?
How to put the a picture before the app starts?
我想在我的应用程序中放一张照片,但不太确定怎么做。
我需要一个新的 activity 吗?如果是这样,activity 将如何理解何时停止并转到真正的程序?
阐明我正在尝试做的事情:当您打开任何应用程序时,我可能认为他们会有我所说的内容。例如,打开 Youtube 应用程序时,在打开真正的应用程序之前,屏幕上会显示 Youtube 的徽标。我认为此屏幕大约需要 3 到 5 秒。
它调用了启动画面
您应该创建一个新的 activity,它有一个计时器。 1-2 秒后,它会启动您的主 activity.
How to implement Splash Screen in android
使用 splash activity 如下所示。示例如下:
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>
我想在我的应用程序中放一张照片,但不太确定怎么做。
我需要一个新的 activity 吗?如果是这样,activity 将如何理解何时停止并转到真正的程序?
阐明我正在尝试做的事情:当您打开任何应用程序时,我可能认为他们会有我所说的内容。例如,打开 Youtube 应用程序时,在打开真正的应用程序之前,屏幕上会显示 Youtube 的徽标。我认为此屏幕大约需要 3 到 5 秒。
它调用了启动画面
您应该创建一个新的 activity,它有一个计时器。 1-2 秒后,它会启动您的主 activity.
How to implement Splash Screen in android
使用 splash activity 如下所示。示例如下:
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>