新建一个Activity 用作启动界面
LoadActivity 类代码如下
public class LoadActivity extends AppCompatActivity {
//图片延迟时间
private final static int LOAD_DISPLAY_TIME = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//取消标题栏和状态栏
//或者采用Style 设置为无标题主题
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN );
setContentView(R.layout.activity_load);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(LoadActivity.this, MainActivity.class);
startActivity(intent);
//加finish()避免返回键跳回加载页面!
finish();
}
}, LOAD_DISPLAY_TIME);
}
}
布局XML代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/load_background">
//背景图片设定
</LinearLayout>