Use `maxLength` property of edittext,
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Customization"
android:maxLength="4"
android:singleLine="true"
/>
it simple way in xml:
android:maxLength="4"
if u require to set 4 character in xml edit-text so,use this
<EditText
android:id="@+id/edtUserCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLength="4"
android:hint="Enter user code" />