Multiline EditText in Android Example


EditTexts in Android Programming extends android.widget.TextView and so are multi-lined by default.

You can make your EditTexts multi-line by added certain attributes to the EditTexts View.

EditText Multiline example Android
EditText Multiline example Android

Lets see an Example :

<EditText
   android:id="@+id/editText1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:lines="10"
   android:minLines="5"
   android:gravity="top|left"
   android:maxLines="15" />

1. android:lines

This tag makes the EditText be exactly as many lines tall as specified as value. It accepts an integer value

2. android:minLines

This tag makes the EditText be at least x many lines tall as specified as value. It accepts an integer value

3. android:maxLines

This tag makes the EditText be at most x many lines tall as specified as value. It accepts an integer value

Note : For multiline EditText by default the cursor and hint text is displayed in the center, you can use android:gravity attribute to set it at top and left of the EditText view :

android:gravity="top|left"

Also remember to set android:layout_height:wrap_content.




Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.