Text.settransformationmethod (NewAsteriskpasswordtransformationmethod ()); Public classAsteriskpasswordtransformationmethodextendsPasswordtransformationmethod {@Override Publiccharsequence gettransformation (charsequence source, view view) {return Newpasswordcharsequence (source); } Private classPasswordcharsequenceImplementsCharsequence {Privatecharsequence Msource; Publicpasswordcharsequence (charsequence source) {Msource= Source;//Store Char sequence } Public CharCharAt (intindex) { return‘*‘;//The important part } Public intLength () {returnMsource.length ();//Return Default } PublicCharsequence subsequence (intStartintend) { returnMsource.subsequence (start, end);//Return Default } }
Textview:setinputtype (). Settransformationmethod ()
In some cases, it may be necessary to run a TextView (perhaps created at runtime or written in an XML file) in a seasonal operation. Since it is not possible to specify it as a password input property through an XML file, how does this work?
There are two methods of TextView:
Setinputtype (int) settransformationmethod (Transformationmethod)
Setinputtype can change the way TextView is entered: contact, Email, Date, time, short Message, Normal Text, Password, and so on. You can also specify a variety of correction options, such as capitalize the first letter of the word, capitalize the sentence, AutoCorrect, and so on.
How to use:
int InputType = Inputtype.type_class_text | Inputtype.type_text_flag_auto_correct | Inputtype.type_text_flag_multi_line | Inputtype.type_text_flag_auto_correct | Inputtype.type_text_variation_short_message; Textview.setinputtype (inputtype);
Settransformationmethod, in turn, can support the conversion of input characters, including the elimination of line breaks, and conversion to masks. How to use:
Textview.settransformationmethod (Passwordtransformationmethod.getinstance ());
In general, if you need to implement your own conversion, you can achieve your goal by implementing the Transformationmethod interface (such as making all the characters you enter a, or entering a display z, input z display a, and so on).
Android EditText Password box By default is small dot how to change to other (*)?