开源项目--来电管理精灵(一) 线程实现SplashScreen

来源:互联网 发布:no python inter 编辑:程序博客网 时间:2024/06/10 04:24

   

现在我就给大家看下我是怎么设计SplashScreen这个页面。

 

代码如下:

 

SplashScreen.java

 

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

public class SplashScreen extends Activity {
  public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

 

    //实现了页面的全屏设置
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

   

         setContentView(R.layout.splashscreen);

 

    //使用了线程来实现SplashScreen效果代码在这里我设置了红色字体5000 即为5秒钟
         new Handler().postDelayed(new Runnable(){

    @Override
    public void run() {
     // TODO Auto-generated method stub
     Intent intent=new Intent(SplashScreen.this,MainScreen.class);
     SplashScreen.this.startActivity(intent);
     SplashScreen.this.finish();
    }
          
         },5000);
        
  }
}

 

 

现在看下我们这个页面的XML文件是怎么实现的吧

 

splashscreen.xml (说明:XML文件名必须为小写字母)

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/splashbg" android:gravity="center">
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/splashlogo"></ImageView>
</RelativeLayout>

 

注意:在AndroidManifest.xml文件中必须加这句否则会出错

<activity android:name="com.tosum.app.SplashScreen" android:screenOrientation="portrait"></activity>