方法一:

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消失的更多相关文章

  1. jq弹框 (1)内容自适应宽度 2(内容框显示,几秒后自动消失)

      <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&q ...

  2. mvc页面中,显示自定义时间格式

    1.在model中,遇到datetime格式的字段,用string来表示 model中 /// <summary> /// 开始时间 /// </summary> [Displ ...

  3. 自定义圆角透明的Dialog

    自定义圆角透明的Dialog 说明 系统默认的Dialog默认是背景不透明的,有时候项目需要Dialog为圆角透明,这个时候的解决方案就是---重写Dialog - 系统样式 - 自定义以后的样式 自 ...

  4. CentOS下date命令 - 显示和设置系统日期与时间

    显示系统日期 要显示系统日期,只要输入: $ date Thu Dec 5 22:55:41 WIB 2013 格式化显示日期 日期有很多格式.如果你不喜欢默认的格式,你可以换一种格式.你可能会想&q ...

  5. linux 获取时间后--自定义时间格式

    自定义时间格式 =================================-===================================== #include <stdio.h ...

  6. Linux date命令 - 显示和设置系统日期与时间

    操作系统上的时间也许只是当做一个时钟.特别在控制台下, 我们通常并不认为时间有什么重要的.但是对于管理员,这种认识是错误的.你知道错误的日期和时间会导致你不能编译程序么? 因为日期和时间很重要,这或许 ...

  7. linux 系统文件类型、系统安装时间、系统启动时间、系统运行时间、设置及显示时间、系统时间和硬件时间

    系统文件类型: 1) $mout 2) df -l:仅列出本地文件系统:-h (--human-readable):-T:文件系统类型 $df -lhf 3) file -s (--special-f ...

  8. Android中控制Dialog呈现的时间

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zinss26914/article/details/36900157 用线程控制dialog的呈现时 ...

  9. 【转】MFC 对话框Border属性设置(None、Thin、Resizing、Dialog Frame)

    对话框的Border属性对应的值设置 Dialog Frame WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_CLIPSIBLINGS | DS_MODALFRAME ...

随机推荐

  1. hdu 1754 I Hate It_线段树

    题意:略 思路:套hdu1166模版改改就行了,要注意的是,网上有的代码是错的,还贴出来... #include <iostream> #include<cstdio> #in ...

  2. iOS 监听 出发 Home键 NSNotificationCenter UIApplicationWillResignActiveNotification

    第一步: 创建2个NSNotificationCenter监听 [[NSNotificationCenter defaultCenter] addObserver:self selector:@sel ...

  3. Android分析第三方应用layout的神器

    hierarchyviewer.bat或者monitor.bat一直都是分析layout的神器,只是.非常多时候不好用,连不上真机,害的我不得不使用模拟器来分析layout. 今天发现了另外一个神器. ...

  4. maven profile参数动态打入

    第一: 1,如果是resources目录下文件profile参数中动态打入,在pom.xml中的build标签中加入如下配置: <resources> <resource> & ...

  5. (转)js prototype 详解

    转载自:http://blog.csdn.net/chaojie2009/article/details/6719353(也是转载的.鄙视一下此人转载不著名出处.) 注意:必须带着怀疑的态度去看这篇文 ...

  6. Windows计算器使用详解

    (1)Backspace:退格,删除当前输入数字中的最后一位 (2)CE:清除,清除显示的数字. (3)C:归零,清除当前的计算. (4)MC:清除存储器中的数值. (5)MR:将存于存储器中的数显示 ...

  7. ajax在ie下返回未定义解决方案

    有时候用ajax进行请求,接收到的数据在火狐下很正常,但在ie浏览器下确是undefined,这是因为后端php输入json时没有统一指定contentType头导致的,只需在php文件中加入head ...

  8. 关于Git和Github

    英文原文:Ten Things You Didn't Know Git And GitHub Could Do Git 和 GitHub 都是非常强大的工具.即使你已经使用他们很长时间,你也很有可能不 ...

  9. Javascript 拖拽雏形中的一些问题——逐行分析代码,让你轻松了解拖拽的原理

    今天我们就来解决上一次拖拽雏形中的一些问题.下面看看有哪些问题? 附上上期的Javascript代码,方便大家查看问题. <script type="text/javascript&q ...

  10. 使用device.js检测设备并实现不同设备展示不同网页

    现在很多时候会用@media来控制页面在不同分辨率的设备商展示不同效果,但是有些时候想在直接在PC上展示一个做好的页面,在mobile展示另一个页面.这个时候可以借助device.js来检测设备,然后 ...