Android延长Toast显示时间的方法

Linux大全评论2.6K views阅读模式

invokeLongTimeToast()函数关键在于调用initToast()方法。而initToast()又会调用execToast()方法,从而引发递归,cnt是序列号,当cnt等于3时停止递归,用它来调节Toast的显示时间。

/**
  * After a time show a <code>Toast</code> again.
  *
  * @param toast
  *            <code>Toast</code>
  * @param cnt
  *            Sequence
  */

private void execToast(final Toast toast, final int cnt) {
  Timer timer = new Timer();
  timer.schedule(new TimerTask() {

   @Override
   public void run() {
    initToast(toast, cnt + 1);
   }

  }, 3000);
 }

 /**
  * Show the <code>Toast</code> and {#execToast}
  *
  * @param toast
  *            <code>Toast</code>
  * @param cnt
  *            Sequence
  */
 private void initToast(Toast toast, int cnt) {
  if (cnt > 2)
   return;
  toast.show();
  execToast(toast, cnt);
 }

企鹅博客
  • 本文由 发表于 2020年8月23日 23:57:35
  • 转载请务必保留本文链接:https://www.qieseo.com/172854.html

发表评论