最近比较闲,所以会陆续出很多基础型Demo和高级点的Demo,,小伙伴们肯定又要骂了,孙子又来装B了
在android应用中,其实闪屏是一个很重要的前期
先上效果图:就是一个页面,没有Logo和公司名几乎就是一张背景,又要挨骂了
很重要?,这不废话吗,不重要为什么每个应用都有呢。
嗯,闪屏第一要做的就是展现自己的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>
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);
,又要挨骂了,这么简单,分明是拿上来赚用户浏览量嘛,逗比
嗯,好吧,挨骂也是要写的额,不因为别的,就因为手痒。
这么简单,还是给个 代码下载 吧