You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.0 KiB
85 lines
3.0 KiB
package com.example.amicool;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
public class SplashActivity extends AppCompatActivity implements View.OnClickListener{
|
|
private int recLen = 5;//跳过倒计时提示5秒
|
|
private TextView tv;
|
|
Timer timer = new Timer(); //定义一个计时器
|
|
private Handler handler;
|
|
private Runnable runnable;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
//定义全屏参数
|
|
int flag= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
|
//设置当前窗体为全屏显示
|
|
getWindow().setFlags(flag, flag);
|
|
setContentView(R.layout.activity_splash);
|
|
initView();
|
|
timer.schedule(task, 1000, 1000);//等待时间一秒,停顿时间一秒
|
|
// /*** 正常情况下不点击跳过*/
|
|
handler = new Handler();
|
|
handler.postDelayed(runnable = new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
//从闪屏界面跳转到首界面
|
|
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
|
|
startActivity(intent);
|
|
finish();
|
|
}
|
|
}, 5000);//延迟5S后发送handler信息
|
|
}
|
|
|
|
private void initView() {
|
|
tv = findViewById(R.id.tv);//跳过
|
|
tv.setOnClickListener(this);//跳过监听
|
|
}
|
|
TimerTask task = new TimerTask() {
|
|
@Override
|
|
public void run() {
|
|
runOnUiThread(new Runnable() { // UI thread
|
|
@Override
|
|
public void run() {
|
|
recLen--;
|
|
tv.setText("跳过 " + recLen);
|
|
if (recLen < 0) {
|
|
timer.cancel();
|
|
tv.setVisibility(View.GONE);//倒计时到0隐藏字体
|
|
}
|
|
}
|
|
});
|
|
}
|
|
};
|
|
/**
|
|
* 点击跳过
|
|
*/
|
|
@Override
|
|
public void onClick(View view) {
|
|
switch (view.getId()) {
|
|
case R.id.tv:
|
|
//从闪屏界面跳转到首界面
|
|
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
|
|
startActivity(intent);
|
|
finish();
|
|
if (runnable != null) {
|
|
handler.removeCallbacks(runnable);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|