Is it possible to add a timer to the actionbar on android?

后端 未结 3 1886
说谎
说谎 2021-02-08 02:29

I\'d like a simple mm:ss timer to be displayed on my actionbar, be able to pick the number of minutes to start counting down from and then call a method once it\'s

3条回答
  •  一生所求
    2021-02-08 02:47

    Yes it's possible to add timer in toolbar action use this code in Java:

    private void startTimer(long duration, long interval) {
    
    CountDownTimer timer = new CountDownTimer(duration, interval) {
    
        @Override
        public void onFinish() {
            //TODO Whatever's meant to happen when it finishes
        }
    
        @Override
        public void onTick(long millisecondsLeft) {
            int secondsLeft = (int) Math.round((millisecondsLeft / (double) 1000));
            timerText.setText(secondsToString(secondsLeft));
        }
    };
    
    timer.start();
    }
    

    and also use menu file defined timer id just like this

    if learn more the visit youtube :)

提交回复
热议问题