由於某種需求,需要在某個Activity中啟動一個ProgressDialog表示正在進行時。但當ProgressDialog起來後,此時按Home鍵,則會報錯,那如何在ProgressDialog顯示的過程中屏蔽掉Home鍵呢?
直接上代碼:
首先重寫
- @Override
- public void onAttachedToWindow() {
- // TODO Auto-generated method stub
- this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
- super.onAttachedToWindow();
- }
然後:
- themeSetProgressDialog = ProgressDialog.show(this, getString(R.string.theme_set_progressbar_title), getString(R.string.theme_set_progressbar_message), true);
- themeSetProgressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);