【Android】安卓设置欢迎页
程序员文章站
2022-05-04 23:33:07
...
安卓设置全屏启动页面,实现一定时间后跳转:
在启动的WelcomeActivity里:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import java.util.Timer;
import java.util.TimerTask;
public class WelcomeActivity extends AppCompatActivity {
public static WelcomeActivity instance = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
setContentView(R.layout.activity_welcome);
instance=this;
final Intent it = new Intent(this, MainActivity.class); //你要转向的Activity
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
startActivity(it); //执行
}
};
timer.schedule(task, 1500); //1.5秒后
}
}
为了结束WelcomeActivity可以在MainActivity里:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
setContentView(R.layout.activity_main);
WelcomeActivity.instance.finish();//结束欢迎页activity
//webView = new FragmentWebView();
//initView();
//initData();
//clickHomeButton();//默认主页面
}
如果需要显示有几秒到主Activity里或者有点击进入主Activity的功能可以在WelcomeActivity里面自己添加。