zoukankan      html  css  js  c++  java
  • 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之前

  • 相关阅读:
    leetcode| Intersection of Two Arrays II
    Spring Boot起步依赖:定制starter
    SpringBoot自动配置的魔法是怎么实现的
    Dubbo中的IoC实现
    必须知道的String知识点
    Dubbo的SPI机制
    为什么要设置HTTP timeout?
    重构代码——简单工厂模式+模板方法模式
    计算机基础——位运算
    系统间HTTP调用代码封装
  • 原文地址:https://www.cnblogs.com/androidxufeng/p/3682130.html
Copyright © 2011-2022 走看看