需要另外建立一个welcome.xml布局,可以在layout下,只需要将背景换成导入的图片即可,代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/welcome">
</LinearLayout>
新建个welcome.java中写入:
public class welcome extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
startActivity(new Intent(welcome.this,MainActivity.class));
finish();
}
},3000);
}
}
另一种写法
public
class
Welcome
extends
Activity{
private
final
int
SPLASH_DISPLAY_LENGHT =
3000
;
//延迟三秒
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
new
Handler().postDelayed(
new
Runnable(){
@Override
public
void
run() {
Intent mainIntent =
new
Intent(Welcome.
this
,Choose.
class
);
Welcome.
this
.startActivity(mainIntent);
Welcome.
this
.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
在AndroidManifest.xml中的<application下面添加第一个Activity(一定要放在第一个位置),代码如下:
<activity
android:name="com.example.welcome.welcome"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:theme=
"@android :style/Theme.NoTitleBar.Fullscreen"
这句话可以加在<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme=
"@android :style/Theme.NoTitleBar.Fullscreen">
下面可以删掉下一个activity的
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>