EditText restricts specified input types, such as numbers and upper – and lower-case letters

<EditText
    android:id="@+id/tv_code"
    style="@style/edt_text"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_marginLeft="4dp"
    android:layout_weight="1"
    android:hint="Please enter"
    android:maxLength="17"
    android:digits="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"/>

Copy the code
With the above setting of the digits attribute, the EditText can only enter numbers and upper – and lower-case letters

An easy way to automatically convert input lowercase letters to uppercase letters and display them on the EditText is to set the EditText’s setTransformationMethod

/ / first is the method of small turn capital public class UpperCaseTransform extends ReplacementTransformationMethod {@ Override protected char []getOriginal() {
        char[] aa = {'a'.'b'.'c'.'d'.'e'.'f'.'g'.'h'.'i'.'j'.'k'.'l'.'m'.'n'.'o'.'p'.'q'.'r'.'s'.'t'.'u'.'v'.'w'.'x'.'y'.'z'};
        return aa;
    }

    @Override
    protected char[] getReplacement() {
        char[] cc = {'A'.'B'.'C'.'D'.'E'.'F'.'G'.'H'.'I'.'J'.'K'.'L'.'M'.'N'.'O'.'P'.'Q'.'R'.'S'.'T'.'U'.'V'.'W'.'X'.'Y'.'Z'};
        returncc; }} / / and then is to set up the editText. SetTransformationMethod (new UpperCaseTransform ());Copy the code
With the above Settings, the EditText is converted to uppercase when the user enters lowercase letters

Automatically hide the entered password

  • Similar to the above principle, set the TransformationMethod to PasswordTransformationMethod, EditText will hide the input password is a black dot
edtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
Copy the code

Did you improve today? Welcome to follow my wechat public number, and make progress with me every day!