当前位置:操作系统 > 安卓/Android >>

Android Service中弹出全局对话框

[java]
<span style="white-space:pre">        </span>View view = View.inflate(StatusBarService.this, R.layout.power_off_dialog, null); 
                AlertDialog.Builder b = new AlertDialog.Builder(StatusBarService.this);   
                b.setView(view); 
                final AlertDialog d = b.create(); 
                d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); //系统中关机对话框就是这个属性 
                //d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);  //窗口可以获得焦点,响应操作 
                //d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);  //窗口不可以获得焦点,点击时响应窗口后面的界面点击事件 
                d.show(); 
                 
                Button yesButton = (Button) view.findViewById(R.id.yes_button); 
                Button canclButton = (Button) view.findViewById(R.id.cancl_button); 
 
                yesButton.setOnClickListener(new View.OnClickListener() { 
 
                    @Override 
                    public void onClick(View v) { 
                        Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); 
                        intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false); 
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
                        startActivity(intent); 
                    } 
                }); 
 
                canclButton.setOnClickListener(new View.OnClickListener() { 
 
                    @Override 
                    public void onClick(View v) { 
                        d.dismiss(); 
                    } 
                }); 


摘自  twoicewoo的专栏
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,