ty_splash_time); tv_time= (TextView) findViewById(R.id.tv_time); mc=new MyCountDownTimer(5000,1000); mc.start();//启动倒计时 handler.postDelayed(new Runnable() { @Override public void run() { Intent intent=new Intent(SplashTimeActivity.this,MainActivity.class); startActivity(intent); } },5000); } private Handler handler=new Handler(); /** * 定义一个倒计时的内部类 */ class MyCountDownTimer extends CountDownTimer { /** * * @param millisInFuture 从开始调用start()到倒计时完成并onfinish()方法被调用的毫秒数 * @param countDownInterval 接收onTick(long)回调的间隔时间 */ public MyCountDownTimer(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); } @Override public void onTick(long l) { tv_time.setText("倒计时"+l/1000); } @Override public void onFinish() { tv_time.setText("正在跳转"); } } }
xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/splasht2" tools:context="com.msn.zn.splashdemo.SplashTimeActivity"> <TextView android:id="@+id/tv_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:textSize="20sp" android:text="闪一下" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" />
</RelativeLayout>
|