Android中控制Dialog呈现的时间

用线程控制dialog的呈现时间,思路很简单,直接show代码了,我也是为了方便自己记录


private void showProgressDialog() {
	pDialog = new ProgressDialog(mContext);

	pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	pDialog.setProgress(100);
	pDialog.setMessage("请稍等一秒...");
	pDialog.setIndeterminate(false);
	pDialog.show();

	WindowManager.LayoutParams lp = pDialog.getWindow().getAttributes();
	lp.gravity = Gravity.CENTER;
	Window win = pDialog.getWindow();
	win.setAttributes(lp);

	// 只呈现1s
	new Thread(new Runnable() {

		@Override
		public void run() {
			long startTime = System.currentTimeMillis();
			int progress = 0;

			while (System.currentTimeMillis() - startTime < 1000) {
				try {
					progress += 10;
					pDialog.setProgress(progress);
					Thread.sleep(100);
				} catch (InterruptedException e) {
					pDialog.dismiss();
				}
			}

			pDialog.dismiss();
		}
	}).start();
}


Android中控制Dialog呈现的时间,布布扣,bubuko.com

Android中控制Dialog呈现的时间

上一篇:android界面设计之布局


下一篇:android Splashy Flash小游戏