自定义Toast显示时长

public void showMyToast(final Toast toast, final int cnt) {  
        final Timer timer = new Timer();  
        timer.schedule(new TimerTask() {  
            @Override  
            public void run() {  
                toast.show();  
            }  
        }, 0, 3000);  
        new Timer().schedule(new TimerTask() {  
            @Override  
            public void run() {  
                toast.cancel();  
                timer.cancel();  
            }  
        }, cnt );  
    }  
Toast toast=Toast.makeText(RegistActivity.this, "这是可以随意设置时间的Toast", Toast.LENGTH_LONG);  
showMyToast(toast, 10*1000);  //设置显示的时间

你可能感兴趣的:(自定义Toast显示时长)