首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >具有完成操作按钮的多行EditText

具有完成操作按钮的多行EditText
EN

Stack Overflow用户
提问于 2010-06-07 07:42:32
回答 10查看 71.6K关注 0票数 131

可以同时设置android:inputType="textMultiLine"android:imeOptions="actionDone"EditText小部件吗?

我想要一个多行编辑框,用键盘上的操作按钮来完成,而不是Enter (回车),但它似乎不起作用。

EN

回答 10

Stack Overflow用户

发布于 2016-12-08 00:30:44

使用

代码语言:javascript
复制
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);

在XML中:

代码语言:javascript
复制
android:inputType="textMultiLine"
票数 227
EN

Stack Overflow用户

发布于 2015-10-19 13:53:05

工作示例!创建以下支持此功能的自定义EditText类,并在xml文件中使用该类。工作代码:

代码语言:javascript
复制
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" />
票数 27
EN

Stack Overflow用户

发布于 2018-12-04 21:27:33

要在Kotlin中做到这一点(也可以选择应用其他配置,如textCapSentences,您可以使用此扩展函数:

代码语言:javascript
复制
// 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)
}

用法:

代码语言:javascript
复制
myEditText.setMultiLineCapSentencesAndDoneAction()
票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2986387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档