package com.suresursus.fresh;
import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
public class FullScreenActivity extends Activity {
private int recLen = 3;
private TextView skip;
Timer timer = new Timer();
private Handler handler;
private Runnable runnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_screen);
timer.schedule(task, 1000, 1000);
handler = new Handler();
handler.postDelayed(runnable = new Runnable() {
@Override
public void run() {
Intent intent = new Intent(FullScreenActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 5000);
skip = (TextView)findViewById(R.id.skip);
skip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FullScreenActivity.this, MainActivity.class);
startActivity(intent);
finish();
if (runnable != null) {
handler.removeCallbacks(runnable);
}
}
});
}
TimerTask task = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
recLen--;
skip.setText("跳过 " + recLen);
if (recLen < 0) {
timer.cancel();
skip.setVisibility(View.GONE);
}
}
});
}
};
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FullScreenActivity"
android:background="#ffffff">
<TextView
android:id="@+id/skip"
android:textColor="#000000"
android:textStyle="bold"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="40dp"
android:layout_marginTop="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
另外想要实现全屏还需要修改AndroidManifest.xml。
<activity android:name=".FullScreenActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>