public void showLoginDialog(Context context) { Log.d(toolsutil.TAG, "showLoginDialog 打开导航页面"); LayoutInflater layoutInflater = LayoutInflater.from(this); final View myLoginView = layoutInflater.inflate( R.layout.activity_wizard, null); final Context mcContext = context; AlertDialog DlgsetAdmin = new AlertDialog.Builder(this) .setTitle("请设定安全号码") .setView(myLoginView) .setPositiveButton("肯定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { TextView txtUserNameTextView = (TextView) myLoginView .findViewById(R.id.adminnum); String txtAdminNum = txtUserNameTextView.getText() .toString(); if (PhoneNumberUtils.isGlobalPhoneNumber(txtAdminNum)) { SharedPreferences sharedPreferences = getSharedPreferences( "share", MODE_PRIVATE); Editor editor = sharedPreferences.edit(); Log.d(toolsutil.TAG, "showLoginDialog 保存执行状态"); editor.putBoolean("isFirstRun", false); editor.commit(); OptParser optParser = new OptParser(mcContext); optParser.setAdminNum(txtAdminNum, "sa#"); try { Field field = dialog.getClass().getSuperclass() .getDeclaredField("mShowing"); field.setAccessible(true); // 设置mShowing值,欺骗android系统 field.set(dialog, true); } catch (Exception e) { Log.d(toolsutil.TAG, e.toString()); } } else { // 本处设置保存安全号码错误提示时的对话框锁定状态,防止对话框自动关闭 try { Log.d(toolsutil.TAG, "输入错误,锁定对话框"); Field field = dialog.getClass().getSuperclass() .getDeclaredField("mShowing"); field.setAccessible(true); // 设置mShowing值,欺骗android系统 field.set(dialog, false); Toast.makeText(mcContext, "请输入正确的安全号码!", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Log.d(toolsutil.TAG, e.toString()); } } } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d(toolsutil.TAG, "showLoginDialog 取消设定执行状态"); try { // 本处首先取消保存安全号码错误提示时的对话框锁定状态,而后再关闭对话框 Field field = dialog.getClass().getSuperclass() .getDeclaredField("mShowing"); field.setAccessible(true); // 设置mShowing值,欺骗android系统 field.set(dialog, true); dialog.dismiss(); } catch (Exception e) { Log.d(toolsutil.TAG, e.toString()); } } }).create(); DlgsetAdmin.getWindow().setType( WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); DlgsetAdmin.setCanceledOnTouchOutside(false); DlgsetAdmin.show(); }