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.


🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.

Follow Us: GitHub | Facebook | Twitter | Instagram