Android程序中欢迎界面

额,在做项目中,肯定首先要用到欢迎界面,下面是我在做项目中用的最简单的一个欢迎界面,即打开程序时,先是显示一张图片,然后等一段时间后图片消失,进入登录界面。直接上代码,有注释也不用解释了:

 首先是Welcom.java

 

 1 import cn.nedu.math.ninebox.R;
 2 import android.app.Activity;
 3 import android.content.Intent;
 4 import android.content.res.Configuration;
 5 import android.os.Bundle;
 6 import android.os.Handler;
 7 import android.os.Message;
 8 import android.view.Window;
 9 import android.view.WindowManager;
10 
11 public class Welcome extends Activity {
12     private Handler handler;
13 
14     @Override
15     public void onCreate(Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17          //设置全屏
18         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  //去掉标题栏(应用程序的名字)
19         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  //隐去状态栏部分(电池等图标和一切修饰部分)
20                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
21         
22     //启动一个线程加载欢迎界面
23         setContentView(R.layout.welcome);
24         handler = new Handler() {
25             public void handleMessage(Message msg) {
26                 if (msg.arg1 == 1) {
27                     Intent intent = new Intent();
28                     intent.setClass(Welcome.this, DengLu.class);
29                     startActivity(intent);
30                     finish();
31                 }
32             }
33         };
34         new Thread() {
35             public void run() {
36                 // TODO Auto-generated method stub
37                 try {
38                     sleep(1500);     //线程暂停1.5秒,单位毫秒
39                     Message msg = handler.obtainMessage();
40                     msg.arg1 = 1;
41                     handler.sendMessage(msg);  //发送消息
42                 } catch (InterruptedException e) {
43                     // TODO Auto-generated catch block
44                     e.printStackTrace();
45                 }
46             }
47         }.start();   //在需要的地方启动线程
48     } 
49                 //当屏幕显示(横屏竖屏发生切换时)调用的方法
50     public void onConfigurationChanged(Configuration newConfig) {
51 
52         super.onConfigurationChanged(newConfig);
53     }
54 }

welcom.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/huanyingtupian"
    android:orientation="vertical" >

</LinearLayout>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。