android程序的启动页面(SplashActivity)

第一种

 1 import android.content.Intent;  
 2 import android.os.Handler;  
 3 import android.os.Message;  
 4 import android.support.v7.app.AppCompatActivity;  
 5 import android.os.Bundle;  
 6 import android.view.KeyEvent;  
 7 import android.view.WindowManager;  
 8   
 9 public class WelcomeActivity extends AppCompatActivity {  
10   
11     @Override  
12     protected void onCreate(Bundle savedInstanceState) {  
13         getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//满屏显示  
14         super.onCreate(savedInstanceState);  
15         setContentView(R.layout.activity_welcome);  
16   
17         handler.sendEmptyMessageDelayed(1,2000);  
18     }  
19   
20     private Handler handler = new Handler(new Handler.Callback() {  
21         @Override  
22         public boolean handleMessage(Message message) {  
23             if (message.what == 1){  
24                   Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);  
25                   startActivity(intent);  
26                   finish();  
27                   
28             }  
29             return false;  
30         }  
31     });  
32   
33     @Override  
34     public boolean onKeyDown(int keyCode, KeyEvent event) {  
35         if (keyCode == KeyEvent.KEYCODE_BACK){  
36             return false;  
37         }  
38         return false;  
39     }  
40 } 

第二种

 1 xml version="1.0" encoding="utf-8"?>  
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
 3     xmlns:app="http://schemas.android.com/apk/res-auto"  
 4     xmlns:tools="http://schemas.android.com/tools"  
 5     android:layout_width="match_parent"  
 6     android:layout_height="match_parent"  
 7     android:background="@drawable/splash_background"  
 8     tools:context=".SplashActivity">  
 9   
10 RelativeLayout> 

 

 1 import android.content.Intent;  
 2 import android.os.Handler;  
 3 import android.support.v7.app.AppCompatActivity;  
 4 import android.os.Bundle;  
 5 import android.view.Window;  
 6 import android.view.WindowManager;  
 7   
 8 public class SplashActivity extends AppCompatActivity {  
 9   
10     @Override  
11     protected void onCreate(Bundle savedInstanceState) {  
12         super.onCreate(savedInstanceState);  
13   
14         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
15                 WindowManager.LayoutParams.FLAG_FULLSCREEN);  
16         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
17   
18         setContentView(R.layout.activity_splash);  
19   
20         new Handler().postDelayed(new Runnable() {  
21             public void run() {  
22                 Intent intent = new Intent();  
23                 intent.setClass(SplashActivity.this, MainActivity.class);  
24                 startActivity(intent);  
25                 finish();  
26             }  
27         }, 1000 * 3);  
28     }  
29   
30     @Override  
31     public void onBackPressed() {  
32         //super.onBackPressed();  
33     }  
34 } 

 

转载于:https://www.cnblogs.com/wangzhengtai/p/8732564.html

你可能感兴趣的:(android程序的启动页面(SplashActivity))