Android进阶篇之引导页系列之Splash闪屏Log

最近比较闲,所以会陆续出很多基础型Demo和高级点的Demo,骂人,小伙伴们肯定又要骂了,孙子又来装B了

在android应用中,其实闪屏是一个很重要的前期

先上效果图:就是一个页面,没有Logo和公司名几乎就是一张背景,又要挨骂了委屈

Android进阶篇之引导页系列之Splash闪屏Log_第1张图片

很重要?发火,这不废话吗,不重要为什么每个应用都有呢。

嗯,闪屏第一要做的就是展现自己的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);
利用handler的延迟函数,然后在run方法中写要去的页面

new Handler().postDelayed(new Runnable() {
			public void run() {
//				Intent it = new Intent();
//				it.setClass(SplashActivity.this, Login.class);
//				startActivity(it);
				finish();
			}
		}, 1000 * 2);

惊恐,又要挨骂了,这么简单,分明是拿上来赚用户浏览量嘛,逗比抓狂

嗯,好吧,挨骂也是要写的额,不因为别的,就因为手痒。快哭了

这么简单,还是给个 代码下载 吧


你可能感兴趣的:(Android进阶篇之引导页系列之Splash闪屏Log)