今天做项目有个需求就是有一个页面需要弹出一个dialog,但是这个dialog不可以影响,这个页面的跳转.这个页面可能跳转也可能不跳转,跳转后,这个dialog,还是显示的,

然而我们平时写的dialog是基于activity的,那么在这种情况下是不可能的,网上搜索了下,提出以下解决办法

在service中弹出dialog

public class ShowDialogService extends Service {

    @Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
} @Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
} @Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
} @Override
@Deprecated
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
String str_username=intent.getExtras().getString("username");
String str_password=intent.getExtras().getString("password");
AlertViewDialog dialog=new AlertViewDialog(ShowDialogService.this);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
dialog.setTitle("提示");
String html="<p>已将您注册为会员</p><p>用户名:"+str_username+"</p><p>密&nbsp;&nbsp;&nbsp; 码:"+str_password+"</p>";
dialog.setMessage(Html.fromHtml(html).toString()); /* AlertDialog.Builder dialog=new AlertDialog.Builder(ShowDialogService.this);
// TextView view=new TextView(ShowDialogService.this);
View view=LayoutInflater.from(ShowDialogService.this).inflate(R.layout.slt_cnt_type, null); LinearLayout linear=(LinearLayout) view.findViewById(R.id.dialog_conent);
LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) linear.getLayoutParams(); //取控件textView当前的布局参数
linearParams.height = 100;// 控件的高强制设成20
linearParams.width = 300;
linear.setOrientation(LinearLayout.VERTICAL);
linear.setLayoutParams(linearParams);
TextView username=new TextView(ShowDialogService.this);
TextView password=new TextView(ShowDialogService.this);
username.setText("用户名:");
password.setText("密 码:");
linear.addView(username);
linear.addView(password);
dialog.setView(view);
final AlertDialog d = dialog.create();
d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
d.show();*/
/* Window window=d.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.dimAmount = 0f;
window.setAttributes(params);
*/
}

这里的alertdialog 是自己写的一个继承的dialog。

这里弹出dialog  创建dialog的方式和以前写dialog的方式是一样的主要是加了一句话

        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();

设置dialog为系统级别的,并且要在show之前

Android之全局的dialog的显示的更多相关文章

  1. Android 7.0 Dialog 无法显示的问题

    app 在 Android 7.0 上登录的时候, Dialog 不显示了,但是半透明背景显示 经过搜索和对比,发现出现该问题是因为重写了 getResources() 方法造成的 .重写该方法是为了 ...

  2. Android应用Activity、Dialog、PopWindow、Toast窗体加入机制及源代码分析

    [工匠若水 http://blog.csdn.net/yanbober 转载烦请注明出处.尊重劳动成果] 1 背景 之所以写这一篇博客的原因是由于之前有写过一篇<Android应用setCont ...

  3. Android中制作自定义dialog对话框的实例

    http://www.jb51.net/article/83319.htm   这篇文章主要介绍了Android中制作自定义dialog对话框的实例分享,安卓自带的Dialog显然不够用,因而我们要继 ...

  4. Android Crash 全局捕获

    Android Crash 全局捕获 首先应该明白的一点是,Android在崩溃后会重新启动崩溃时的那个Activity,如果你的Activity在初始化的时候就直接崩溃,那么你将连续得到 Crash ...

  5. Android开发之自定义Dialog简单实现

    本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中. 首先来看一下效果图: 首先是activity的界面 点击了上述图片 ...

  6. 【转】 Android常用实例—Alert Dialog的使用

    Android常用实例—Alert Dialog的使用 AlertDialog的使用很普遍,在应用中当你想要用户做出“是”或“否”或者其它各式各样的选择时,为了保持在同样的Activity和不改变用户 ...

  7. Android单个按钮自定义Dialog

    代码改变世界 Android单个按钮自定义Dialog dialog_layout.xml <?xml version="1.0" encoding="utf-8& ...

  8. Android仿QQ ios dialog,仿QQ退出向上菜单

    Android仿QQ ios dialog,仿QQ退出向上菜单 EasyDialog两种模式 仿QQ退出向上菜单,自己定义向上菜单              github地址:https://gith ...

  9. 解决Android Graphical Layout 界面效果不显示

    解决Android Graphical Layout 界面效果不显示 qq463431476

随机推荐

  1. [Linux] - Docker 常用命令

    # 运行docker # -it表示前端运行 docker run -it centos /bin/echo haha # 后端运行并映射80端口 docker run -dt -p : --name ...

  2. ecmobile中IOS版本中界面文字不显示的解决

    查找以下方法. - (BOOL)setCurrentLanguageName:(NSString *)name{        BeeLanguage * lang = [self findLangu ...

  3. HackerRank "Flatland Space Stations"

    A bit Greedy can achieve O(m) - the mid station between 2 adjacent cities has the longest distance w ...

  4. C# dataTable 排序

    DataView dv = ds.DefaultView; dv.Sort = "header asc"; ds = dv.ToTable(); C# dataTable 排序

  5. DDGSpring2016 Demos

    I followed the course http://brickisland.net/DDGSpring2016/, and here is the screenshot of my coding ...

  6. InstallShield打包设置相对路径

    InstallShield打包设置相对路径 在使用Installshield 打包安装文件时,添加打包文件时默认使用绝对路径,但是工程文件转移时(复制到其它位置时)编译时就会找不到安装文件,这样很不方 ...

  7. HDU 2795 Billboard(区间求最大值的位置update的操作在query里做了)

    Billboard 通过这题,我知道了要活用线段树的思想,而不是拘泥于形式, 就比如这题 显然更新和查询放在一起很简单 但如果分开写 那么我觉得难度会大大增加 [题目链接]Billboard [题目类 ...

  8. python 类变量和实例变量

    super(cls, inst) 获得的是 cls 在 inst 的 MRO 列表中的下一个类.  实例的属性存储在实例的__dict__中,类属性和方法存储在类的__dict__中.查找属性时,先检 ...

  9. 分布式ID生成器 zz

    简介 这个是根据twitter的snowflake来写的.这里有中文的介绍. 如上图所示,一个64位ID,除了最左边的符号位不用(固定为0,以保证生成的ID都是正数),还剩余63位可用. 下面的代码与 ...

  10. Integration Services创建ETL包

    http://www.cnblogs.com/chiniao/archive/2009/12/23/1630595.html  (转载) Microsoft Integration Services ...