[英]How can i use countDown timer in android
I want use countDown timer in my application and i should create such as this : Click too see image我想在我的应用程序中使用倒计时计时器,我应该创建这样的:点击查看图片
How can i create countDownTimer such as above design?我如何创建countDownTimer,如上述设计?
Maybe this can help you :也许这可以帮助你:
https://github.com/tsuryo/Android-Countdown-Timer https://github.com/tsuryo/Android-Countdown-Timer
<com.tsuryo.androidcountdown.Counter
android:id="@+id/counte1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:max_time_unit="DAY"
app:text_color="#2196F3"
app:text_size="36dp"
app:textual_description="true"
app:counter_font="DIGITAL_BOLD" />
and Java:和爪哇:
mCounter = findViewById(R.id.counter);
mCounter.setDate("2019-07-19T18:33:00"); //countdown starts
private void downTimer(){
new CountDownTimer(120*1000,1000) {
@Override
public void onTick(long millisUntilFinished) {
long second = (millisUntilFinished / 1000) % 60;
long minutes = (millisUntilFinished/(1000*60)) % 60;
textViewCountDownTimer.setText(minutes + ":" + second);
}
@Override
public void onFinish() {
textViewCountDownTimer.setText("Finish");
}
}.start();
}
Example of showing a 30 second countdown in a text field:在文本字段中显示 30 秒倒计时的示例:
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
}
}.start();
Visit https://developer.android.com/reference/android/os/CountDownTimer.html访问https://developer.android.com/reference/android/os/CountDownTimer.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.