首页 > 其他分享 >使用ScheduledExecutorService延时关闭一个全屏的对话框

使用ScheduledExecutorService延时关闭一个全屏的对话框

时间:2023-04-06 22:43:41浏览次数:40  
标签:Runnable 对话框 void 全屏 dialog ScheduledExecutorService import public


自定义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执行周期性或定时任务


标签:Runnable,对话框,void,全屏,dialog,ScheduledExecutorService,import,public
From: https://blog.51cto.com/u_5454003/6174203

相关文章

  • Android 11全屏显示
    @OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//去掉标题栏this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(ActivityLoginBinding.inflate(getLayoutInflater()......
  • 它把RabbitMQ的复杂全屏蔽了,我朋友用它后被老板一夜提拔为.NET架构师
    它把RabbitMQ的复杂全屏蔽了,我朋友用它后被老板一夜提拔为.NET架构师 本文技术源自外企,并已在多个世界500强大型项目开发中运用。本文适合有初/中级.NET知识的同学阅读。(支持.NET/.NETFramework/.NETCore) RabbitMQ作为一款主流的消息队列工具早已广受欢迎。相比于其......
  • android 解决ScrollView嵌套ListView的问题,不能全屏,全屏不能显示下面控件
    在开发中遇到ScrollView嵌套ListView的问题,最开始发出不能全屏,效果是这样的;但我想要的效果是这样的:下面看一下布局文件:<?xmlversion="1.0"encoding="utf-8"?><ScrollViewxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_p......
  • 55个手机JAVA全屏触屏游戏
    55个游戏我就不一一列举名字了,适合所有触屏手机,全触屏游戏,大部分测试通过,太多了我也没一个一个看,保证能玩就行了thunder://QUFodHRwOi8vd3d3Ljc4eXguY29tL3NvcnQvbWRvd24vMS81NSVCOCVGNiVDQSVENiVCQiVGQUpBVkElQzglQUIlQzYlQzElQjQlQTUlQzYlQzElRDMlQ0UlQ0YlQjcucmFyWlo=......
  • js 头像上传(图片截取) 插件 全屏高清版 源码
    先上图片 index.html<!DOCTYPEhtml><html><head><metaname="viewport"content="width=device-width"/><title>ccp</title><linkhref="Content/ccp.css"rel="stylesheet"......
  • 全屏高度的固定导航条
    全屏高度的固定导航条接下来我们创建一个左边是全屏高度的固定导航条,右边是可滚动的内容。实例https://www.tzffs.com/mnst14/ul{list-style-type:none;margin:0;padding:0;width:25%;margin:0px;padding:0px;color:gray;">#f1f1f1;height:100%;/*全屏......
  • 第五篇 html5 - 新特性【 网络监听接口 + 全屏接口 】
    html5新增网络监听接口1、online2、offlineonline网络联通的时候触发这个事件window.addEventListener("online",function(){ console.log("连接上网络了!"......
  • vue 后台管理系统 全屏
    toggleScreen(){if(this.screen){//判断全屏状态this.$refs.components_layout_side.$el.requestFullscreen()}else{if(document.exitFullscr......
  • Qt5.12实战之模态与非模态对话框使用
    模态对话框使用创建对话框资源创建成功后工程中会出对话框的h及cpp文件和.ui文件双击打开UI文件,向设计窗口中拖入按钮控件并选择栅格布局创建模态对话框并显......
  • element-plus的el-dialog对话框组件自定义样式未生效
    修改dialog组件样式必须在非scoped环境下,再加一个style标签,并给需要加的dialog一个类名eg:createDialog<stylelang="scss"scoped>...</style><stylelang="scss">.crea......