设置dialog显示,自定义时间到后dialog消失
2013-07-25 18:00
337 查看
方法一:
方法二:
public class MyDialog extends Dialog { private int FLAG_DISMISS = 1; private boolean flag = true; public MyDialog(Context context) { super(context); setTitle("自动消失对话框测试!"); } @Override public void show() { super.show(); mThread.start(); } @Override public void dismiss() { super.dismiss(); flag = false; } private Thread mThread = new Thread(){ @Override public void run() { super.run(); while(flag){ try { Thread.sleep(2000); Message msg = mHandler.obtainMessage(); msg.what = FLAG_DISMISS; mHandler.sendMessage(msg); } catch (InterruptedException e) { e.printStackTrace(); } } } }; private Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if(msg.what == FLAG_DISMISS) dismiss(); } }; }
方法二:
自定义一个定时器: public static class TimeCount extends CountDownTimer { public TimeCount(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); } @Override public void onFinish() { // TODO Auto-generated method stub alertDialog.dismiss();//alertDialog是你的对话框 } } 然后在你自己的程序中AlertDialog部分中添加: TimeCount timer = new TimeCount(7000, 1000);//具体时间自定 timer.start();
相关文章推荐
- 设置dialog显示,自定义时间到后dialog消失
- 自定义Dialog动态设置全屏显示,背景透明度,背景黑暗度
- 自定义Dialog,去除系统默认黑色背景以及边框并设置dialog的显示位置
- android--自定义ProgressDialog显示位置(其它Dialog子类都可以设置)
- android 自定义Dialog背景透明及显示位置设置
- Android Dialog设置宽度显示不正常的问题(自定义设置Dialog的宽高)
- android 自定义Dialog背景透明及显示位置设置
- 自定义Dialog,去除系统默认黑色背景以及边框并设置dialog的显示位置
- Android 自定义Dialog背景透明及显示位置设置
- 自定义Toast 可以根据自己的需求 设置显示时间
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- Android 自定义对话框,可设置大小和显示位置,并设置点击其他位置不消失
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- 自定义Dialog设置全屏显示和背景透明
- Android 自定义Dialog背景透明及显示位置设置
- 自定义Dialog设置显示位置