Android Word-Wrap EditText text
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" />
EditText word wrap
I have removed all unnecessary attributes and put only required attribute android:maxLines="20",
So it looks like this,
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:maxLines="20" />
EditText with word-wrap, without line breaks, and with keyboard action set to next
I found out you have to do this by code because some XML attributes get ignored in particular cases.
In your layout, make sure you do not set textMultiline
as input type, then use the following code:
mEditText.setMaxLines(Integer.MAX_VALUE); // Or specify a lower value if you want
mEditText.setHorizontallyScrolling(false);
I've been trying to add text wrap to my edittext, and nothing looks right
Set max lines in EditText:
android:maxLines="5"
or any number instead of 5.
Related Topics
How to Put My Libraries in Front of Android.Jar by Editing Build.Gradle in Android-Studio
How to Forward My Localhost Ip-Address to an Android Emulator
How to Scale a Streaming Bitmap In-Place Without Reading The Whole Image First
Error:Execution Failed for Task ':App:Kaptdebugkotlin'
How to Access The Second Mic Android Such as Galaxy 3
Android V21 Theme.Appcompat Color Accent Is Ignored, No Padding on Dialogs
Mobile Chrome Fires Resize Event on Scroll
Android and Symbian Nfc Mobile Development Questions and Answers (Faq)
Set Drag Margin for Android Navigation Drawer
Android 4.3: Ble: Filtering Behaviour of Startlescan()
How to Open Specific Contact Chat Screen in Various Popular Chat/Social-Networks Apps
Getting The Current Position of a Viewpager
How to Setup Multiple Alarms in Android
How to Get Background Color from Current Theme Programmatically