自定义style,设置全屏属性
<resources>        <style name="AppTheme" parent="android:Theme.Black"/>      <style name="processDialog" >          <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->           <item name="android:windowFullscreen">true</item>            <item name="android:windowIsTranslucent">false</item><!--半透明-->            <item name="android:windowNoTitle">true</item><!--无标题-->            <item name="android:windowBackground">@android:color/transparent</item><!--背景透明-->            <item name="android:backgroundDimEnabled">true</item><!--模糊-->            <item name="android:backgroundDimAmount">0.5</item>           <item name="android:alpha">0.3</item>       </style>      </resources>  

代码中加载这个view并把view set到dialog上,这样全屏的dialog就完成了
mView = LayoutInflater.from(this).inflate(R.layout.process_dialog, null);  processDialog = new Dialog(context, R.style.processDialog);  processDialog.setCancelable(false);processDialog.setContentView(mView);  mAutoCloseDialog = new AutoCloseDialog(processDialog);mAutoCloseDialog.show(Prefs.DIALOG_DISPLAY_TIME);


接下来用一个封装好的类,做一个延时关闭的效果
import java.util.concurrent.Executors;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.TimeUnit;import android.app.Dialog;public class AutoCloseDialog{          private Dialog dialog;      private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();            public AutoCloseDialog(Dialog dialog){          this.dialog = dialog;      }            public void show(long duration){              Runnable runner = new Runnable() {              public void run() {                  dialog.dismiss();              }          };          executor.schedule(runner, duration, TimeUnit.MILLISECONDS);        dialog.show();    }        } 


其他用法示例:
Here is a class with a method that sets up a ScheduledExecutorService to beep every ten seconds for an hour:
import static java.util.concurrent.TimeUnit.*; class BeeperControl {    private final ScheduledExecutorService scheduler =       Executors.newScheduledThreadPool(1);    public void beepForAnHour() {        final Runnable beeper = new Runnable() {                public void run() { System.out.println("beep"); }            };        final ScheduledFuture<?> beeperHandle =            scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);        scheduler.schedule(new Runnable() {                public void run() { beeperHandle.cancel(true); }            }, 60 * 60, SECONDS);    } }


ScheduledExecutorService执行周期性或定时任务

更多相关文章

  1. Android(安卓)关键字 收集
  2. 简叙 Activity 生命周期及android 返回按钮扑捉
  3. 不匀速移动的Animaiton实例XML
  4. Android中的Shape属性
  5. Android(安卓)ConstraintLayout常用属性
  6. Android(安卓)Property System
  7. 设置APP运行界面为竖屏,禁止屏幕旋转
  8. [Android]ListView小技巧
  9. 安卓 EditText属性的总结

随机推荐

  1. QT android platform SDK installed erro
  2. 如何查看USB方式连接Android设备的外接设
  3. Android SDK 源代码编译
  4. android webrtc构建过程
  5. 谁说Android的动画不廉价(三)之共享元素动
  6. 浅谈Android中的线程的通信及Handle机制
  7. Android String Placeholders
  8. Android退出程序(三)——Android事件总线
  9. usb 配置
  10. Android 系統存在設計漏洞,釣魚網站隨時出