没点击跳过自然进入主页,点击跳过之后立即进入主页
1.欢迎页布局activity_sp.xml放一张背景图(图片随你便啦)再放一个盛放倒计时的TextView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/a">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
2.主要java代码
package com.cwj.test;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
public class SpActivity extends AppCompatActivity implements View.OnClickListener {
private int recLen = 5;//跳过倒计时提示5秒
private TextView tv;
Timer timer = new Timer();
private Handler handler;
private Runnable runnable;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//定义全屏参数
int flag= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//设置当前窗体为全屏显示
getWindow().setFlags(flag, flag);
setContentView(R.layout.activity_sp);
initView();
timer.schedule(task, 1000, 1000);//等待时间一秒,停顿时间一秒
/**
* 正常情况下不点击跳过
*/
handler = new Handler();
handler.postDelayed(runnable = new Runnable() {
public void run() {
//从闪屏界面跳转到首界面
Intent intent = new Intent(SpActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 5000);//延迟5S后发送handler信息
}
private void initView() {
tv = findViewById(R.id.tv);//跳过
tv.setOnClickListener(this);//跳过监听
}
TimerTask task = new TimerTask() {
public void run() {
runOnUiThread(new Runnable() { // UI thread
public void run() {
recLen--;
tv.setText("跳过 " + recLen);
if (recLen < 0) {
timer.cancel();
tv.setVisibility(View.GONE);//倒计时到0隐藏字体
}
}
});
}
};
/**
* 点击跳过
*/
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv:
//从闪屏界面跳转到首界面
Intent intent = new Intent(SpActivity.this, MainActivity.class);
startActivity(intent);
finish();
if (runnable != null) {
handler.removeCallbacks(runnable);
}
break;
default:
break;
}
}
}
这里style里改了样式,没有标题栏Theme.AppCompat.Light.NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>