Android 在服务Service中创建Dialog对话框
来源:互联网 发布:数据库怎么恢复 编辑:程序博客网 时间:2024/06/01 08:42
一般我们都是在Activity中创建dialog的,无论是系统的AlertDialog还是我们自定义的Dialog。
我们只需设置title,message等信息,然后show出来即可。
可是在服务中呢,没有activity,dialog没有了依赖,那么怎么办呢? 这时,dialog就要以系统对话框的形式弹出了。在我们取得Dialog对象后,需给它设置类型,即:
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
看看这个TYPE的解释
/** * Window type: system window, such as low power alert. These windows * are always on top of application windows. * In multiuser systems shows only on the owning user's window. */ public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3;
在这里别忘了在Manifest中加上权限
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
最后来段示例代码
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); builder.setMessage("Hello,My name is Message."); builder.setNegativeButton("CANCEL", null); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 具体操作 } }); final Dialog dialog = builder.create(); dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); dialog.show();
如有错误或不清楚的地方,还望路过大神批评改正,共同进步。
1 0
- Android 在服务Service中创建Dialog对话框
- android在Service中弹出Dialog对话框
- Android在Service中弹出对话框(Dialog)
- 如何在service中显示对话框dialog
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- Android在Service中弹出对话框(Dialog),即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- Android中对话框(Dialog)的创建方法
- Android中对话框(Dialog)的创建方法
- Android中对话框Dialog的创建
- Android: Service中创建窗口Dialog
- Android NDK: From Elementary to Expert Episode 3
- 【Spring】Spring事务
- 视频剪切---ffmpeg命令的使用
- tensorflow学习笔记二:入门基础
- C# 泛型对象的使用
- Android 在服务Service中创建Dialog对话框
- 判断两个string是否相等
- 第七次c++实验 愚蠢的富人
- switch语句
- 大型网站技术架构-4 瞬时响应:网站的高性能架构
- 进程fork处理
- poj 2420 A Star not a Tree?(模拟退火求费马点)
- iOS 10和macOS中的卷积神经网络
- ZooKeeper数据模型