如果我发布了一个警告框,我想阻止TouchEvent,实际上我可以按下屏幕,我可以访问受密码保护的屏幕。然后如何保护对屏幕的访问,就像我的密码是真的一样。我的对话框由以下代码给出:
void showDialog() {
final String myPassword = getResources().getString(R.string.password);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(R.string.connection);
// Set an EditText view to get user input
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
String hashedPassword = Utilities.md5(value);
if (myPassword.equalsIgnoreCase(hashedPassword)) {
//code
} else {
Toast.makeText(getApplicationContext(),
"Mot de passe incorrect", Toast.LENGTH_LONG).show();
admin = false;
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
});
alert.setNegativeButton("Annuler",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
Intent intent = getIntent();
finish();
startActivity(intent);
}
});
alert.show();
}
答案 0 :(得分:1)
我不确定我是否理解,但试试这个:
http://developer.android.com/reference/android/app/Dialog.html#setCancelable(boolean)
alert.setCancelable(false);