每个Android应用启动之后都会出现一个启动界面,显示产品的LOGO、公司的LOGO或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间。
效果图:
点击马上进入或者等待3秒欢迎页面结束。
首先配置AndroidManifest.xml文件中的Activity
<activity
android:name="com.example.intentdemo.Firstpage"
<!--去掉这个Activity的ActionBar-->
android:theme="@android:style/Theme.NoTitleBar"
android:label="wetalk">
<!--将这个Activity设置为主程序入口-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
package com.example.intentdemo;
import java.util.Timer;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Firstpage extends Activity{
Button enter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstpage);
enter = (Button) findViewById(R.id.enter);
//3秒之后执行
myhHandler.sendEmptyMessageDelayed(111, 3000);
//点击按钮进入主Activity
enter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(Firstpage.this, MainActivity.class);
startActivity(intent);
}
});
}
/**
* 处理页面跳转到主Activity
* */
Handler myhHandler = new Handler(){
@Override
public void handleMessage(Message msg){
switch (msg.what) {
case 111:
Intent intent = new Intent();
intent.setClass(Firstpage.this, MainActivity.class);
startActivity(intent);
break;
default:
break;
}
}
};
}