I have been trying to get my EditText box to word wrap, but can't seem to do it.
I have dealt with much more complicated issues while developing Android applications, and this seems like it should be a straightforward process.
However, the issue remains, and I have a large text box that is only allowing me to enter text on one line, continuing straight across, scrolling horizontally as I enter text.
Here is the XML code for the EditText object from my layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/myWidget48"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView
android:id="@+id/myScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/widget37"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/txtNotes"
android:layout_width="300px"
android:layout_height="120px"
android:scrollbars="vertical"
android:textSize="18sp"
android:gravity="left"
android:layout_marginTop="10dip"
android:inputType="textCapSentences"
>
</EditText>
</LinearLayout>
</ScrollView>
</LinearLayout>
Besides finding the source of the issue, I found the solution. If android:inputType
is used, then textMultiLine must be used to enable multi-line support. Also, using inputType supersedes the code android:singleLine="false"
. If using inputType, then, to reiterate, textMultiLine must be used or the EditText object will only consist of one line, without word-wrapping.
Edit: Thank you Jacob Malliet for providing further good advice on this. He suggested to set the boolean scrollHorizontally property to false, 'android:scrollHorizontally="false"'
.
Example XML code:
<EditText
android:id ="@+id/edtInput"
android:layout_width ="0dip"
android:layout_height ="wrap_content"
android:layout_weight ="1"
android:inputType="textCapSentences|textMultiLine"
android:maxLines ="4"
android:maxLength ="2000"
android:hint ="@string/compose_hint"
android:scrollHorizontally="false" />
Ok i figured it out, you must set android:scrollHorizontally="false"
for your EditText
in your xml. I'm pretty sure this should work.
Assume that you just want to have one line at first then expand it to 5 lines and you want to have maximum 10 lines.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/etMessageBox"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:autoLink="all"
android:hint="@string/message_edit_text_hint"
android:lines="5"
android:minLines="1"
android:gravity="top|left"
android:maxLines="10"
android:scrollbars="none"
android:inputType="textMultiLine|textCapSentences"/>
By increasing android:lines
you can define expand it how many lines.
you must add the following attribute to your edittext.
android:inputType="textMultiLine"
Also if you set the height or set the maxlines of edittext to a specific value, it will scroll when you typed much character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With