Multiline EditText with Done SoftInput Action Label on 2.3
Well, after re-reading the TextView
and EditorInfo
docs, it has become clear that the platform is going to force IME_FLAG_NO_ENTER_ACTION
for multi-line text views.
Note that
TextView
will automatically
set this flag for you on multi-line
text views.
My solution is to subclass EditText
and adjust the IME options after letting the platform configure them:
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection connection = super.onCreateInputConnection(outAttrs);
int imeActions = outAttrs.imeOptions&EditorInfo.IME_MASK_ACTION;
if ((imeActions&EditorInfo.IME_ACTION_DONE) != 0) {
// clear the existing action
outAttrs.imeOptions ^= imeActions;
// set the DONE action
outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
}
if ((outAttrs.imeOptions&EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
}
return connection;
}
In the above, I'm forcing IME_ACTION_DONE
too, even though that can be achieved through tedious layout configuration.
Edittext in multiline with actionDone issue in Android
Add
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
in XML:
android:inputType="textMultiLine"
Android EditText: Done instead of Enter or Word Wrap instead of Multi Line
android:inputType="textEmailAddress|textEmailSubject"
You need to set the input type as email address or email subject. Either one will give you your desired result. shouldAdvanceFocusOnEnter()
is a private method in TextView which determines whether to enter a new line or move focus to next field.
Allow multi-line in EditText view in Android?
By default all the EditText
widgets in Android are multi-lined.
Here is some sample code:
<EditText
android:inputType="textMultiLine" <!-- Multiline input -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
android:gravity="top|start" <!-- Cursor Position -->
android:maxLines="10" <!-- Maximum Lines -->
android:layout_height="wrap_content" <!-- Height determined by content -->
android:layout_width="match_parent" <!-- Fill entire width -->
android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>
Why does Android multiline EditText with android:imeOptions=actionNext work in Google Keep?
You can set imeOptions=actionNext
in XML & at runtime setRawInputType
to TYPE_TEXT_FLAG_MULTI_LINE
. This way you can achieve this behavior.
According to docs setRawInputType
is used for:
Directly change the content type integer of the text view, without
modifying any other state.
Example:
XML:
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Activity#onCreate:
binding.editText.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
or InputType.TYPE_TEXT_FLAG_MULTI_LINE)
Android [ENTER]-key action of a multiline edittext in a dialog
I found out that setting the raw inputtype of the EditText to multiline is working where the "normal" input type isn't.
final EditText remark = new EditText(MyClass.this);
remark.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
This did it for me.
Related Topics
How to Use Icons and Symbols from "Font Awesome" on Native Android Application
Support Fragmentpageradapter Holds Reference to Old Fragments
Background Listview Becomes Black When Scrolling
Android Viewpager with Bottom Dots
How to Obtain Signing Certificate Fingerprint (Sha1) for Oauth 2.0 on Android
Recyclerview Itemtouchhelper Buttons on Swipe
Android Studio - Android Emulator Wifi Connected with No Internet
Camera Orientation Issue in Android
Actionbar Up Navigation with Fragments
How to Set Emoji by Unicode in a Textview
Disabling of Edittext in Android
Refreshing Data in Recyclerview and Keeping Its Scroll Position
Android: How to Rotate a Bitmap on a Center Point
How to Get Text on an Actionbar Icon
Android Automatic Horizontally Scrolling Textview