android欢迎界面是非常实用的,之前有写过一篇android欢迎界面淡入淡出效果,偶然在网上发现一个不错的,很基础的欢迎界面的例子。
我设置这个欢迎界面为3秒,如果不想等待这3秒,可以直接点击跳过。
主要的代码如下:
public class SplashScreen extends Activity {
protected int _splashTime = 3000;
private Thread splashTread;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final SplashScreen sPlashScreen = this;
// thread for displaying the SplashScreen
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized(this){
wait(_splashTime);
}
} catch(InterruptedException e){ }
finally {
finish();
Intent i = new Intent();
i.setClass(sPlashScreen, Main.class);
startActivity(i);
stop();
}
}
};
splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
synchronized(splashTread){
splashTread.notifyAll();
}
}
return true;
}
}
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="@color/blueish"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/android"
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>