解:需要设置属性
editText.setImeOptions(EditorInfo.IME_ACTION_SEND); editText.setSingleLine(false); editText.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
editText.setImeOptions(EditorInfo.IME_ACTION_SEND);
editText.setSingleLine(false);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
<EditText
android:id="@+id/input_text"
android:layout_width="match_parent"
android:layout_height="40dp"
android:imeOptions="actionDone"
android:inputType="text"
app:layout_constraintTop_toBottomOf="@+id/hello"/>
EditText editText = findViewById(R.id.input_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
Toast.makeText(MainActivity.this,"done",Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
IME英文全称Input Method Editors