【问题标题】:How can i use countDown timer in android我如何在android中使用倒数计时器
【发布时间】:2017-06-03 07:06:03
【问题描述】:

我想在我的应用程序中使用 countDown 计时器,我应该创建这样的: Click too see image

我怎样才能创建类似上述设计的countDownTimer?

【问题讨论】:

标签: android android-timer


【解决方案1】:

在文本字段中显示 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

【讨论】:

  • 请在我的帖子中查看我的图片。我想创建这样的
  • 您需要为此进行自定义布局。就像上面的代码一样,有 mTextFied。从只显示几秒钟开始,然后根据需要即兴编写您的代码。
【解决方案2】:

也许这可以帮助你:

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

【讨论】:

  • 你好兄弟,每天怎么样?例如倒计时总是从上午 11:15 开始,到第二天上午 11:00 结束?
【解决方案3】:
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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多