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.



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap