Set input text max length limit in EditText android xml

How to specify entered text limitation on EditText using xml layout file.

Android EditText entered text limitation can be set through activity_main.xml file using android:maxLength=”  ” attribute. With the help of this attribute edittext cannot get more then setting max length characters. So here is the complete step by step tutorial for Set input text max length limit in EditText android xml.

android-project-download-code-button

How to Set input text max length limit in EditText android xml.

Code for MainActivity.java file.

package com.example.edittextmaxlengthxml_android_examples.com;
import android.app.Activity;
import android.os.Bundle;


public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.example.edittextmaxlengthxml_android_examples.com.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:inputType="textPersonName"
 android:maxLength="5" >

<!-- Setting up Max Lenth as 5 char. -->
 
 </EditText>

</RelativeLayout>

Screenshot:

Set input text max length limit in EditText android xml

Click Here to download Set input text max length limit in EditText android xml project.

Leave a Reply

Your email address will not be published. Required fields are marked *