java - 如何在Android键盘上显示换行按钮?

标签 java android android-keypad

我正在使用 TextInputLayout 及其多行属性在我的应用程序中构建一个文本区域,以让用户写入超过 1 行,我以编程方式构建它(无 xml)

TextInputLayout textInputLayout = new TextInputLayout(context);
textInputLayout.setLayoutParams(new TextInputLayout.LayoutParams(TextInputLayout.LayoutParams.MATCH_PARENT, TextInputLayout.LayoutParams.WRAP_CONTENT));

TextInputEditText field = new TextInputEditText(context);
field.setText(text);
field.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
field.setLayoutParams(new TextInputLayout.LayoutParams(TextInputLayout.LayoutParams.MATCH_PARENT,(int) (100 * dp)));
textInputLayout.addView(field);
myLinearLayout.addView(textInputLayout); // add text to layout

上面的代码创建了我的文本区域,但没有显示换行按钮,而是显示了submit按钮。

这是当前结果:

enter image description here

这是预期结果(来自另一个应用程序):

enter image description here

我必须添加哪个属性才能像第二个图像一样显示换行按钮?

最佳答案

How to get the keyboard to show a return key?

尝试将 IMEOptions 设置为 None。

field.setImeOptions(EditorInfo.IME_ACTION_NONE);

还要检查 EditText 是否已变为 SingleLine,这也会导致出现完成按钮。

关于java - 如何在Android键盘上显示换行按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58274965/

相关文章:

java - 如何在spring boot secuirty中为具有不同请求方法类型的同一url赋予不同的角色权限

java - 资源包中的值作为 formatDate 中的模式

android - 无法启动 Activity ComponentInfo

java - Android Spinner 无法正确返回 ID

android - 以编程方式禁用键盘缓存Android

java - LDAP服务器返回结果控制?

java - 如何对@Any 注释属性进行双向映射?

android - 在android应用程序中显示cpu,内存信息

android - 如何像其他应用程序的任何文本类型一样存储 Android 键盘 Activity ,并在后台通过互联网发送它?

android - 如何在对话框关闭时隐藏键盘