效果圖:
頁面布局:
二:activity的編寫,用到時間空間戳
package com.example.administrator.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
/** 跳轉時間倒計時頁面
* Created by Administrator on 2016/12/23.
*/
public class JumpActivity extends Activity {
TextView textView;
int time=3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jump);
textView= (TextView) findViewById(R.id.textview);
handler.postDelayed(runnable,3000);
}
Handler handler=new Handler();
Runnable runnable=new Runnable() {
@Override
public void run() {
time--;
handler.postDelayed(this,2000);
textView.setText("跳轉:"+time+"秒");
if(time==0){
Intent intent=new Intent(JumpActivity.this,TestActivity.class);
startActivity(intent);
finish();
}else {
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(JumpActivity.this,TestActivity.class);
startActivity(intent);
//結束線程
handler.removeCallbacks(runnable);
finish();
}
});
}
}
};
}