三秒跳转

package com.bwie.zixun;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private static final int MAG = 123;
    private int i = 3;
    private TextView textView;
    private MyHanlder myHanlder = new MyHanlder();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = (TextView) findViewById(R.id.miao);
        myHanlder.sendEmptyMessageDelayed(0, 1000);

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, Deng.class);
                startActivity(intent);
                finish();
            }
        });
    }

    class MyHanlder extends Handler {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            i--;
            textView.setText(i + "s");
            if (i == 0) {
                myHanlder.removeCallbacksAndMessages(null);
                Intent intent = new Intent(MainActivity.this, Deng.class);
                startActivity(intent);
                finish();
            } else {
                myHanlder.sendEmptyMessageDelayed(0, 1000);

            }
        }
    }

}

===================布局

<?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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="3s"
        android:id="@+id/miao"
        android:textSize="20dp" />

    <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/eee" />

</RelativeLayout>

猜你喜欢

转载自blog.csdn.net/qq_43131935/article/details/82751566