倆秒修改文字,再停留倆秒,跳轉下個界面

package com.example.myapplication;

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

public class MainActivity extends AppCompatActivity {

    private TextView tv_text;
    private Handler handler = new Handler();
    private Runnable run =  new Runnable() {
        @Override
        public void run() {


            tv_text.setText("我在學習Android");

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(2000);
                        Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                        startActivity(intent);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }).start();


        }

    };


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

        initView();

        handler.postDelayed(run,2000);
    }



    private void initView() {
        tv_text = (TextView) findViewById(R.id.tv_text);
    }
}
相關文章
相關標籤/搜索