定制Toast的显示时间-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
定制Toast的显示时间

背景:

为吐鲁番等地区用户提供了全套网页设计制作服务,及吐鲁番网站建设行业解决方案。主营业务为成都网站建设、网站设计、吐鲁番网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

    缺省状态下,Toast显示时间大约在1~2秒时间,有时需要让弹出窗显示更长的时间。

案例:

    可通过调用CountDownTimeer例来达到此目标。

public class ToastActivity extends Activity
{
    AlertDialog dialog;
   
     static CountDownTimer timer =null;
     Toast toast;
     @Override
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                

                // creating toast and setting properties

                toast = new Toast(this);
                TextView textView=new TextView(this);
                textView.setTextColor(Color.BLUE);
                textView.setBackgroundColor(Color.TRANSPARENT);
                textView.setTextSize(20);
                textView.setText("This Toast will Display for 20 Seconds in Center of The Screen");
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);

                toast.setView(textView);
               

               //    Toast Display tTime Settings

               
                // Create the CountDownTimer object and implement the 2 methods
                // show the toast in onTick() method  and cancel the toast in onFinish() method
                // it will show the toast for 20 seconds (20000 milliseconds 1st argument) with interval of 1 second(2nd argument)
 
                timer =new CountDownTimer(20000, 1000)
                {
                    public void onTick(long millisUntilFinished)
                    {
                        toast.show();
                    }
                    public void onFinish()
                    {
                        toast.cancel();
                    }

                }.start();
               
          }
}

通过调用timer.cancel()可以取消Toast的显示。

结果:

    定制Toast的显示时间


本文名称:定制Toast的显示时间
网站URL:http://scgulin.cn/article/pjepjp.html