1、修改自动生成的 activity_welcome.xml 文件,主要代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/welcome_bg"
tools:context=".WelcomeActivity" >
</RelativeLayout>
2、修改 AndroidManifest.xml 文件,修改闪屏界面为全屏模式
<activity
android:name="cn.edu.bztc.walkersimulate.WelcomeActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/title_activity_welcome" >
</activity>
3、修改 WelcomeActivity,实现停顿 3 秒后跳转
方式 1:利用动画持续时间,动画结束后跳转,主要代码如下:
public class WelcomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
RelativeLayout layoutWelcome=(RelativeLayout) findViewById(R.id.layoutWelcome);
AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f,1.0f);
alphaAnimation.setDuration(3000);
layoutWelcome.startAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent intent=new Intent(WelcomeActivity.this,LoginActivity.class);
startActivity(intent);
}
});
}
}
方式 2:使用 Handler 完成跳转
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent(WelcomeActivity.this,LoginActivity.class);
startActivity(intent);
}
},3000);
方式 3:使用多线程完成跳转
new Thread() {
public void run() {
try {
Thread.sleep(3000);
Intent intent = new Intent(WelcomeActivity.this,
LoginActivity.class);
startActivity(intent);
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();