Android之全局的dialog的显示

今天做项目有个需求就是有一个页面需要弹出一个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之前

转载于:https://www.cnblogs.com/androidxufeng/p/3682130.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值