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?
This one works for me.
But you have to look at Octavian Damiean's comment, he's right.
This is deprecated
In xml of EditText iclude this attribute: android:password="true"
Edit
You need to use
PasswordTransformationMethod.getInstance()
instead ofnew PasswordTransformationMethod()
.Here's a new way of putting dots in password
add android:inputType = "textPassword"
I found when doing this that in order to set the gravity to center, and still have your password hint show when
using inputType
, theandroid:gravity="Center"
must be at the end of your XML line.See this link text view android:password
This applies for
EditText
as well, as it is a known direct subclass ofTextView
.