Android中较为简单的自动跳转式欢迎界面设计
步骤一: 编辑activity_welecome.xml如下:
<LinearLayout 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/welecome"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".WelecomeActivity" >
<Button
android:id="@+id/btn_close"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="256dp"
android:contentDescription="@string/close_wele"
android:background="@drawable/close_welecome"
/>
</LinearLayout>
界面显示如下:
步骤二:修改AndroidManifest.xml文件,将welecomeActivity设为默认Activity
<activity
android:name="com.huawei.moby.WelecomeActivity"
android:label="@string/title_activity_welecome"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
步骤三: 在welecomeActivity.java中设置计时器,控制Intent跳转到目标Activity即可
package com.huawei.moby;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class WelecomeActivity extends Activity {
private Button btn_close;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welecome);
final Intent it = new Intent(this, LoginActivity.class);
Timer timer = new Timer();
btn_close = (Button) findViewById(R.id.btn_close);
// 定时跳转
TimerTask task = new TimerTask() {
@Override
public void run() {
startActivity(it); //执行
}
};
timer.schedule(task, 1000 * 3);
// 直接跳转
btn_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(it);
}
});
}
}
是比较简单的一种跳转实现。