在android应用中,其实闪屏是一个很重要的前期
先上效果图:就是一个页面
嗯,闪屏第一要做的就是展现自己的Logo,如果Logo好看,一眼就能留住用户,如果Logo和我的名字一样,,用户肯定是屈指可数啊;第二,也是闪屏最重要的作用,就是利用闪屏的时间来做很多数据加载操作,这个也不难想到,如果直接进入数据比较多的主页时,那加载主页的承载负量就特别大,甚至会导致ANR<Application no responsed>,所以基本上上线的产品大多数都会在闪屏的时候加载数据;第三,检查更新。。。
splash.xml文件,很简单,就是一个空的,设置背景,如果想设置自己的Logo可以直接写在里面
- <RelativeLayout 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/splash"
- tools:context=".SplashActivity" >
- </RelativeLayout>
SplashActivity.java,也很简单,没什么可说的。
- import android.os.Bundle;
- import android.os.Handler;
- import android.app.Activity;
- import android.view.Window;
- import android.view.WindowManager;
- public class SplashActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.splash);
- new Handler().postDelayed(new Runnable() {
- public void run() {
- // Intent it = new Intent();
- // it.setClass(SplashActivity.this, Login.class);
- // startActivity(it);
- finish();
- }
- }, 1000 * 2);
- }
- }
下面的代码,是将SplashActivity页面设置全屏,没有状态栏
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- new Handler().postDelayed(new Runnable() {
- public void run() {
- // Intent it = new Intent();
- // it.setClass(SplashActivity.this, Login.class);
- // startActivity(it);
- finish();
- }
- }, 1000 * 2);