Android welcome欢迎界面

MainActivity.class

package cn.bgs.welcome_teacher;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity implements OnClickListener {
private TextView mTv_now,mTv_count;
private int index=5;
private boolean flag=true;
private ThreadOne thread1;
private boolean click=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
thread1=new ThreadOne();
thread1.start();
}
private void initView() {
mTv_now=(TextView) findViewById(R.id.mTv_now);
mTv_count=(TextView) findViewById(R.id.mTv_count);

mTv_now.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this, MainActivity_b.class);
startActivity(intent);
thread1.interrupt();
mTv_count.setVisibility(View.INVISIBLE);
click=true;
}
private class ThreadOne extends Thread{
@Override
public void run() {
while (flag) {
try {
Thread.sleep(1000);
handler.sendEmptyMessage(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
super.run();
}
}

@Override
protected void onPause() {
super.onPause();
flag=false;
}

private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what==0) {
if (index>0) {
index--;
mTv_count.setText(""+index);
if (index==0) {
if (!click) {

Intent intent=new Intent(MainActivity.this, MainActivity_b.class);
startActivity(intent);
mTv_count.setVisibility(View.INVISIBLE);
}
}
}
}
}
};

}


MainActivity_b.class

package cn.bgs.welcome_teacher;


import android.app.Activity;
import android.os.Bundle;


public class MainActivity_b extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
}
}

你可能感兴趣的:(android开发)