前言
我们在打开一款APP时例如QQ、微信或者微博时都会发现在正式进入程序时,都会有一个启动界面,这种界面的出现主要是因为程序在运行时会有一定的加载时间,如果不加启动界面,会出现短暂时间的白屏现象,反而给用户营造一种程序卡顿的现象,影响用户体验,添加一个启动界面能非常好的解决这个问题。启动界面常用来为程序加载提供好的用户体验,当然也有向微博那样也可以插入广告,达到盈利的目的。遂以本篇文章记录启动界面的设置。
正文
首先新建两个Activity,AppstartActivity和MainActivity,进入AppstartActiv的layout界面,点击Text进入程序编码界面输入以下代码
<LinearLayout 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"
tools:context=".AppStartActivity"
android:background="@drawable/app_start">
</LinearLayout>
(图片资源来源于网络)
回到AppstartActivity中,输入以下代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_start);
ActionBar actionbar = getSupportActionBar();
if (actionbar != null) {
actionbar.hide();
}//去除顶部导航栏
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent(AppStartActivity.this,MainActivity.class);//活动跳转
startActivity(intent);
AppStartActivity.this.finish();
}
},1000);//这里1000表示1秒,可根据需要改变
}
操作结果如下: