思考着用后台service来弹出对话框,于是在网上搜到了这样的一种方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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(); } |
转自:http://blog.csdn.net/twoicewoo/article/details/7448584