3

In one of my application I'm trying to put a password confirmation in a dialog. The dialog is entirely build programmatically. I had some problem to set the type of the input to password but it's working. Later, I just noticed that the keyboard has the auto-suggestion option.

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(...); 
builder.setIcon(...); 
builder.setMessage(...); 
builder.setCancelable(false); 

EditText etForcePassword = new EditText(mContext); 
etForcePassword.setSingleLine(); 
etForcePassword.setHint(...);
etForcePassword.setImeOptions(EditorInfo.IME_ACTION_DONE);
etForcePassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
etForcePassword.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS | EditorInfo.TYPE_TEXT_VARIATION_FILTER); 
builder.setView(etForcePassword, top, right, bottom, left); 

AlertDialog alertDialog = builder.create(); 
alertDialog.show();`

I saw a lot of solution by setting the InputType or simply using XML configuration but it's not fitting my application.

Thanks in advance.

Schnapse
  • 485
  • 1
  • 5
  • 19

2 Answers2

6

To turn off auto-suggestion, change this line:

etForcePassword.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS | EditorInfo.TYPE_TEXT_VARIATION_FILTER);

to this line:

etForcePassword.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
CzarMatt
  • 1,773
  • 18
  • 22
  • Thanks ! But I can't understand why. `EditorInfo` class is implementing `InputType` interface. – Schnapse Jun 13 '17 at 19:44
  • `InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD` breaks some keyboards and also stylus input because it "tells software keyboard, that content of this field should not be added to any vocabulary, synchronized through network, added to usage statistics or anything like this" ([source](https://stackoverflow.com/a/61592084/1014048)). Try [this approach](https://stackoverflow.com/a/14333765/1014048) instead. – Ivan Mir Oct 23 '20 at 01:04
-1

Insert below onCreate->setContentView():

getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);

Jay makwana
  • 97
  • 1
  • 4