可以同时设置android:inputType="textMultiLine"
和android:imeOptions="actionDone"
的EditText
小部件吗?
我想要一个多行编辑框,用键盘上的操作按钮来完成,而不是Enter (回车),但它似乎不起作用。
发布于 2016-12-08 00:30:44
使用
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
在XML中:
android:inputType="textMultiLine"
发布于 2015-10-19 13:53:05
工作示例!创建以下支持此功能的自定义EditText类,并在xml文件中使用该类。工作代码:
package com.example;
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.example.ActionEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="textAutoCorrect|textCapSentences|textMultiLine" />
发布于 2018-12-04 21:27:33
要在Kotlin中做到这一点(也可以选择应用其他配置,如textCapSentences
,您可以使用此扩展函数:
// To use this, do NOT set inputType on the EditText in the layout
fun EditText.setMultiLineCapSentencesAndDoneAction() {
imeOptions = EditorInfo.IME_ACTION_DONE
setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or InputType.TYPE_TEXT_FLAG_MULTI_LINE)
}
用法:
myEditText.setMultiLineCapSentencesAndDoneAction()
https://stackoverflow.com/questions/2986387
复制相似问题