Password singleline how to
I need to programatically set 开发者_如何学PythonEditText
to display text like password and I also need this EditText
to be single line.
I know how to make EditText
to display text like password:
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
I also know how to display EditText
on single line:
editText.setEllipsize(TruncateAt.END);
editText.setSingleLine();
I don't know how to combine these two. When I put these lines of code together, the EditText
is not working. Even the software keyboard can't be displayed for it.
Does anyone of you guys know how to solve my problem? Thanks in advance for your answer(s).
I finally did it. For those who have the same problem the correct approach is to combine the two requests but in the different order than I did it before. So you should do:
editText.setEllipsize(TruncateAt.END);
editText.setSingleLine();
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
I hope this will help someone.
To make EditText
conceal password characters, add the password
attribute to the relevant element in your layout.
http://developer.android.com/reference/android/widget/TextView.html#attr_android:password
It can also be done programmatically
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
//.....
editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
editText.setTransformationMethod(new PasswordTransformationMethod());
In XML file Type
android:singleLine="true"
精彩评论