背景:
為吐魯番等地區用戶提供了全套網頁設計制作服務,及吐魯番網站建設行業解決方案。主營業務為成都網站建設、網站設計、吐魯番網站設計,以傳統方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業、用心的態度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
缺省狀態下,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);
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);
// 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的顯示時間
網頁路徑:http://m.kartarina.com/article28/pjepjp.html
成都網站建設公司_創新互聯,為您提供網站導航、全網營銷推廣、移動網站建設、品牌網站設計、品牌網站制作、云服務器
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯