该文章实现的是很简单的app开始界面,加入的作用是不让主要内容突然出现显得突兀。启动界面就是单纯的一张图片,进度条,等待三秒自动进入app。
1,添加一个Java文件,命名为splashactivity。代码内容:
package com.example.liu.roommanager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
public class SplashActivity extends Activity{
private final int SPLASH_DISPLAY_LENGHT = 3000; //延迟3秒
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this, RoomListActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
2 为splashactivity添加对应的xml文件,命名为**activity_splash **
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:background="@drawable/bbgg">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome!"
android:textStyle="italic"
android:textColorHighlight="@color/colorPrimary"
android:layout_gravity="center"
android:textSize="40dp"
android:layout_marginBottom="80px"/>
<ProgressBar
android:id="@+id/progressBarLarge"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@android:color/holo_green_light"
android:progressTint="@color/colorPrimary"/>
</LinearLayout>
3 将AndroidManifest里面的代码稍做修改,目的是将splashactivity作为default activity
更改代码如下:
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这样就可以了。