I need to create a login form with 'username' 'password' fields and two buttons 'login' and 'cancel' in my android application.
I am using an alert dialog with edittext inside that.
This is the code I used to create password edittext..
final EditText Password = new EditText(this);
Password.setGravity(Gravity.CENTER);
Password.setHint("Password");
Password.setWidth(200);
Password.setTransformationMethod(new PasswordTransformationMethod());
login_alert.addView(Password);
My issue is that, plain text is shown instead of 'dots' when i open a softkeypad to edit the password. (It is shown as dots when not in softkeypad mode)
Can anyone suggest a solution?
My search for a similar solution for Visual Studio 2015/Xamarin lead me to this thread. While setting the
EditText.InputType
toAndroid.Text.InputTypes.TextVariationVisiblePassword
properly hid the password during user entry, it did not 'hide' the password if it was visible before the EditText Layout was rendered (before the user submitted their password entry). In order to hide a visible password after the user submits their password and the EditText Layout is rendered, I usedEditText.TransformationMethod = PasswordTransformationMethod.Instance
as suggested by LuxuryMode.The only way that worked for me using code (not XML) is this one:
To set password enabled in EditText, We will have to set an "inputType" attribute in xml file.If we are using only EditText then we will have set input type in EditText as given in below code.
Password enable attribute is
But if we are implementing Password EditText with Material Design (With Design support library) then we will have write code as given bellow.
@Note: - In Android SDK 24 and above, "passwordToggleEnabled" is by default true. So if we have the customs handling of show/hide feature in the password EditText then we will have to set it false in code as given above in .
To add above line, we will have to add below line in root layout.