用线程的方法实现Android应用的欢迎界面

原创文章,转载请指明出处并保留原文url地址

一般情况下,我们进入一个Android应用都会出现一个欢迎界面,或者提示用户操作的数页提示界面,界面一般都是全屏的。

本我们程序实现这个全屏界面欢迎页。

网上有如下两种方法:

clip_image002

clip_image004

程序创建完成后目录结构如下:

clip_image006

其中代码如下:

ActivityDemo.java

/*

* Copyright (C) 2010 welcome authors

*

* @author shao

*

* @date 2013.9.21

*

* @blog http://www.iigrowing.cn/

*

* 本程序是android客户端软件演示程序

*

*/

package cn.iigrowing.android.welcome.fullscreen;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Window;

import android.view.WindowManager;

public class ActivityDemo extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

/** 全屏设置,隐藏窗口所有装饰 **/

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

/** 标题是属于View的,所以窗口所有的修饰部分被隐藏后标题依然有效,需要去掉标题 **/

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.welcome);

Start();

}

public void Start() {

new Thread() {

public void run() {

try {

// 延迟5.5秒钟

Thread.sleep(5500);

} catch (InterruptedException e) {

e.printStackTrace();

}

// 启动 新Activity

Intent intent = new Intent();

intent.setClass(ActivityDemo.this, MainActivity.class);

startActivity(intent);

finish();

}

}.start();

}

}

MainActivity.java

/*

* Copyright (C) 2010 welcome authors

*

* @author shao

*

* @date 2013.9.21

*

* @blog http://www.iigrowing.cn/

*

* 本程序是android客户端软件演示程序

*

*/

package cn.iigrowing.android.welcome.fullscreen;

import android.app.Activity;

import android.os.Bundle;

public class MainActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}

welcome.xml

<?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:background="@drawable/welcome"

android:orientation="vertical" >

</LinearLayout>

main.xml

<?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" >

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello" />

</LinearLayout>

 

源代码 下载地址

发表评论