一对一视频聊天APP源码,使用Handler开启倒计时相关的代码
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private int count=5;
private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
//倒计时 五 四 三 二 一
String[] str = new String[]{"一","二","三","四","五"};
tv_text.setText(str[count]);
return false;
}
});
private TextView tv_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
tv_text = (TextView) findViewById(R.id.tv_text);
new Thread(new Runnable() {
@Override
public void run() {
while (count>0){
try {
Thread.sleep(1000);
handler.sendEmptyMessage(0);
} catch (Exception e) {
e.printStackTrace();
}
count--;
}
Intent intent = new Intent(MainActivity.this, HomeActivity.class);
startActivity(intent);
}
}).start();
}
}
以上就是一对一视频聊天APP源码,使用Handler开启倒计时相关的代码, 更多内容欢迎关注之后的文章