新建一个Activity.java(或者ther->Android Activity)
public class OpenActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//隐藏标题栏以及状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
/**标题是属于View的,所以窗口所有的修饰部分被隐藏后标题依然有效,需要去掉标题**/
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_open);
handler.sendEmptyMessageDelayed(0,3000);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
getHome();
super.handleMessage(msg);
}
};
public void getHome(){
Intent intent = new Intent(OpenActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
再建一个Activity.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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal"
android:src="@drawable/tm_s"/>
<!--android src属性指定imageView里面要显示的资源文件的来源路径,也就是在欢迎界面显示的图片,在这里我已经预先上传了一张图片了-->
</LinearLayout>
清单文件改一下
<activity
android:name=".OpenActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_open" >
</activity>
三个延迟跳转
准备工作一张图片
<?xml version="1.0" encoding="utf-8"?>
<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>
java开始画面类写
package com.lin.mr.mystudy;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import java.util.Timer;
import java.util.TimerTask;
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
//方法一:开启一个子线程执行跳转任务
// new Thread(){
// @Override
// public void run() {
// super.run();
// try {
// Thread.sleep(2000);
// Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
// startActivity(intent);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }.start();
//方法二:使用Handler发送延迟消息
// new Handler(new Handler.Callback() {
// @Override
// public boolean handleMessage(Message msg) {
// Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
// startActivity(intent);
// return false;
// }
// }).sendEmptyMessageDelayed(0,2000);
//方法三:使用Java计时器
Timer timer = new Timer();
timer.schedule(new MyTask(),2000);//定时器延时执行任务的方法
}
//方法三:使用Java计时器
class MyTask extends TimerTask{
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
startActivity(intent);
}
}
}