gpt4 book ai didi

android - 如何使用 ActionDone 按钮(不带 Enter 按钮)实现多行 EditText

转载 作者:IT老高 更新时间:2023-10-28 23:16:36 29 4
gpt4 key购买 nike

我有用于在消息(电子邮件、短信)上输入内容的 EditText。我希望在单击 ActionDone 按钮时立即发布消息。我为此使用以下代码:

message.setOnEditorActionListener((textView, i, keyEvent) -> {
switch (i) {
case EditorInfo.IME_ACTION_DONE:
if (messageCanBePosted()) {
SoftKeyboard.hide(message);
postMessage();
return true;
} else {
return false;
}
default:
return false;
}
});

但我也希望这个消息字段是多行的,就像在任何其他信使应用程序中一样。我可以用这条线来实现它:

android:inputType="textMultiLine"

问题是在添加这一行之后 ActionDone 按钮开始像 Enter 按钮一样起作用。所以我捕获 EditorInfo.IME_ACTION_DONE 的回调永远不会被调用。因此,每次用户按下该按钮时,光标都会移动到新行而不是发布消息。

如何同时保留 EditText 的多行行为(在多行上显示文本的能力)和 ActionDone 按钮?

最佳答案

使用

editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);

在 XML 中:

android:inputType="textMultiLine"

来源:Multi-line EditText with Done action button

关于android - 如何使用 ActionDone 按钮(不带 Enter 按钮)实现多行 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36338563/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com