背景:
创新互联公司主营甘德网站建设的网络公司,主营网站建设方案,重庆APP开发公司,甘德h5微信小程序定制开发搭建,甘德网站营销推广欢迎甘德等地区企业咨询缺省状态下,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的显示。
结果:
    
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享名称:定制Toast的显示时间-创新互联
URL标题:http://www.cqwzjz.cn/article/copjip.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 