0

I use android:imeOptions="actionSend", so I add android:inputType="text", but the EditText shows only one line. Why?

I want the EditText to show many lines and android:imeOptions="actionSend" to work.

<EditText
    android:id="@+id/reply_edit"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/comment_layout_bg"
    android:gravity="center_vertical"
    android:inputType="text"
    android:imeOptions="actionSend"
    android:maxLines="4"
    android:minHeight="36dp"
    android:textSize="16dp"/>

Screenshot

dakab
  • 5,379
  • 9
  • 43
  • 67
Egos Zhang
  • 1,334
  • 10
  • 18

2 Answers2

0

Well from Android documentation I found the following:

Most soft input methods provide a user action button in the bottom corner that's appropriate for the current text field. By default, the system uses this button for either a Next or Done action unless your text field allows multi-line text (such as with android:inputType="textMultiLine"), in which case the action button is a carriage return. However, you can specify additional actions that might be more appropriate for your text field, such as Send or Go.

So for multi-line. instead of

android:inputType="text"

use

android:inputType="textMultiLine" 

Okay the above was not your solution , however for limited no of lines(3). you can use the code bellow

TextView tv = (TextView)findViewById(R.id.editText);
if (tv != null) {
    tv.setHorizontallyScrolling(false);
    tv.setLines(3);
}

You can get multiline now.

Another solution is use the combination of actionDone and MUlti-line like the following

package com.gs;

import android.content.Context;
import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.EditText;

public class ActionEditText extends EditText
{
   public ActionEditText(Context context)
   {
       super(context);
   }

   public ActionEditText(Context context, AttributeSet attrs)
   {
       super(context, attrs);
   }

   public ActionEditText(Context context, AttributeSet attrs, int defStyle)
   {
       super(context, attrs, defStyle);
   }

   @Override
   public InputConnection onCreateInputConnection(EditorInfo outAttrs)
   {
       InputConnection conn = super.onCreateInputConnection(outAttrs);
       outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
       return conn;
   }
}

<com.gs.ActionEditText
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:imeOptions="actionDone"
    android:inputType="textAutoCorrect|textCapSentences|textMultiLine" />
Abdullah
  • 935
  • 9
  • 18
  • It is not work.I have seen what you write. But it mean you set android:inputType="textMultiLine" the action button will become a carriage return. – Egos Zhang Jul 25 '16 at 05:52
0

You can extend EditText and build your own EditText and override onCreateInputConnection method perform your scenarion for action_send. But user can enter four line full text without new lines.

Refer this link

Community
  • 1
  • 1
Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74