Fixed Length Android Edittext


To make an EditText have a fixed length you need to add android: maxLength in <EditText> tag.

⛏️ android:MaxLength : Set an input filter to constrain the text length to the specified number. [integer]

Example

<EditText
    android:id="@+id/editText1"
    android:maxLength="20"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:ems="10" >

The EditText will only allow 20 characters, if you try entering any further it won't get added up.