-4

我想在我的应用程序中使用倒数计时器,我应该创建这样的: 点击查看图片

我怎样才能创建 countDownTimer 如上述设计?

4

3 回答 3

1
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();
}
于 2020-01-16T22:26:50.520 回答
1

也许这可以帮助你:

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" />

和Java:

mCounter = findViewById(R.id.counter);
mCounter.setDate("2019-07-19T18:33:00"); //countdown starts
于 2019-07-18T15:27:23.447 回答
0

在文本字段中显示 30 秒倒计时的示例:

new CountDownTimer(30000, 1000) {

    public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
    }

    public void onFinish() {
         mTextField.setText("done!");
    }

}.start();

访问https://developer.android.com/reference/android/os/CountDownTimer.html

于 2017-06-03T09:37:04.267 回答