如題,這裏要實現的是一個歡迎界面。
當用戶打開程序時,會啓動一個歡迎界面,然後會跳轉到主界面或者登陸界面等等目標界面。
實現的過程如下:
1,當程序打開後,啓動歡迎Activity。
2,啓動一個線程,完成定時跳轉的功能。
3,啓動目標界面,並且銷燬歡迎Activity。
下面是實現過程:
1,在drawable中導入圖片資源;
2,在layout中新建歡迎界面;代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/welcome" >
</LinearLayout>
3,創建歡迎Activity,實現顯示歡迎界面,跳轉功能。代碼如下:
package com.example.xzh_musicplayer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
public class MusicWelcomeActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mp_welcome_layout);
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent=new Intent(MusicWelcomeActivity.this,TestMenuActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
finish();
}
}).start();
}
}