我想让我的应用看起来更专业,所以我决定添加一个启动画面。
我应该如何进行实现呢?
我想让我的应用看起来更专业,所以我决定添加一个启动画面。
我应该如何进行实现呢?
当前回答
Create an activity: Splash Create a layout XML file: splash.xml Put UI components in the splash.xml layout so it looks how you want your Splash.java may look like this: public class Splash extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); int secondsDelayed = 1; new Handler().postDelayed(new Runnable() { public void run() { startActivity(new Intent(Splash.this, ActivityB.class)); finish(); } }, secondsDelayed * 1000); } } change ActivityB.class to whichever activity you want to start after the splash screen check your manifest file and it should look like
<活动 android: name = "。屏” android: label = " @string / app_name " > > < /活动 <活动 android: name = "。飞溅” android: label = " @string / title_activity_splash_screen " > <意图过滤器> <action android:name="android.intent.action. main " /> <category android:name="android.intent.category. launcher " /> < /意图过滤器> > < /活动
其他回答
有时用户打开SplashActivity并立即退出,但应用程序仍然在SPLASH_SCREEN_DISPLAY_LENGTH后转到MainActivity。
为了防止它:在SplashActivity中,你应该在移动到MainActivity之前检查SplashActivity是否结束
public class SplashActivity extends Activity {
private final int SPLASH_SCREEN_DISPLAY_LENGTH = 2000;
@Override
public void onCreate(Bundle icicle) {
...
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!isFinishing()) {//isFinishing(): If the activity is finishing, returns true; else returns false.
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}, SPLASH_SCREEN_DISPLAY_LENGTH);
}
}
}
希望这对你有所帮助
Create an activity: Splash Create a layout XML file: splash.xml Put UI components in the splash.xml layout so it looks how you want your Splash.java may look like this: public class Splash extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); int secondsDelayed = 1; new Handler().postDelayed(new Runnable() { public void run() { startActivity(new Intent(Splash.this, ActivityB.class)); finish(); } }, secondsDelayed * 1000); } } change ActivityB.class to whichever activity you want to start after the splash screen check your manifest file and it should look like
<活动 android: name = "。屏” android: label = " @string / app_name " > > < /活动 <活动 android: name = "。飞溅” android: label = " @string / title_activity_splash_screen " > <意图过滤器> <action android:name="android.intent.action. main " /> <category android:name="android.intent.category. launcher " /> < /意图过滤器> > < /活动
我在android中使用线程制作Flash屏幕。
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
public class HomeScreen extends AppCompatActivity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen_home);
Thread thread = new Thread(){
public void run(){
try {
Thread.sleep(3 * 1000);
Intent i = new Intent(HomeScreen.this, MainActivity.class);
startActivity(i);
} catch (InterruptedException e) {
}
}
};
thread.start();
}
}
你可以在你的onCreate方法中添加这个
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// going to next activity
Intent i=new Intent(SplashScreenActivity.this,MainActivity.class);
startActivity(i);
finish();
}
},time);
初始化你的时间值在毫秒,因为你想…
private static int time=5000;
欲了解更多详细信息,请从此链接下载完整代码…
https://github.com/Mr-Perfectt/Splash-Screen
创建一个活动,让我们活动命名为“a”,然后创建一个名为mysscreen .xml的xml文件,在其中设置一个启动画面图像作为背景,然后使用倒计时计时器从一个活动导航到另一个活动。要知道如何使用倒计时定时器看到我的答案在这个问题的TimerTask在Android?