Android imeOptions“actionNext”以编程方式 - 如何跳转到下一个字段?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3459168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:17:24  来源:igfitidea点击:

imeOptions "actionNext" programmatically - how to jump to next field?

androidandroid-widget

提问by Laimoncijus

In layout XML it is possible to specify android:imeOptions="actionNext"which adds Nextbutton in virtual keyboard and by clicking on it - focus jumps to the next field.

在布局 XML 中,可以指定虚拟键盘中的android:imeOptions="actionNext"哪个添加Next按钮,并通过单击它 - 焦点跳转到下一个字段。

How to do this programmatically - e.g. based on some event trigger focus to go to the next field?

如何以编程方式执行此操作 - 例如基于某些事件触发焦点转到下一个字段?

回答by Firewall_Sudhan

You can use the constants from EditorInfo class for the IME options. like,

您可以将 EditorInfo 类中的常量用于 IME 选项。喜欢,

editText.setImeOptions(EditorInfo.IME_ACTION_NEXT);

回答by Justin

Search for the next focusable field and than invoke requestFocus().

搜索下一个可聚焦的字段,然后调用requestFocus()

TextView nextField = (TextView)currentField.focusSearch(View.FOCUS_RIGHT);
nextField.requestFocus();

回答by ziniestro

Just suggestion, if you are using

只是建议,如果您正在使用

     EditTextSample.setImeOptions(EditorInfo.IME_ACTION_DONE); 

it doesn't work, make sure that your EditText is using a single line.

它不起作用,请确保您的 EditText 使用单行。

Eg:

       editTextSample.setSingleLine();

例如:

       editTextSample.setSingleLine();

回答by IntelliJ Amiya

There is always necessity to add extra keys apart from default keys available in virtual QWERTYkeyboard.

除了虚拟QWERTY键盘中可用的默认键之外,总是需要添加额外的键。

Using XML

使用 XML

<EditText android:text="@+id/EditText01" 
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:imeOptions="actionDone"/>

By Programmatic Way

By Programmatic Way

An EditorInfois most useful class when you have to deal with any type of user input in your Android application.

EditorInfo当您必须在 Android 应用程序中处理任何类型的用户输入时,An是最有用的类。

IME_ACTION_DONE:This action performs a “done” operation for nothing to input and the IME will be closed.

IME_ACTION_DONE:此操作执行“完成”操作,无需输入任何内容,IME 将关闭。

 EditTextSample.setImeOptions(EditorInfo.IME_ACTION_DONE);

For more information you may visit http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html

有关更多信息,您可以访问http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html

回答by kuzdu

The kotlin pendant

科特林吊坠

editText.imeOptions = EditorInfo.IME_ACTION_DONE

回答by Handelika

editText.setLines(1);
editText.setSingleLine(true);
editText.setImeOptions(EditorInfo.IME_ACTION_GO);

I solve the problem make sure with single line and go next editText when click enter

我解决了这个问题,确保使用单行并在单击 Enter 时转到下一个 editText

回答by Mete

In my case, set an imeOptions fix the problem.

就我而言,设置 imeOptions 可以解决问题。

edtAnswer.maxLines = 1
edtAnswer.inputType = InputType.TYPE_CLASS_TEXT
edtAnswer.imeOptions = EditorInfo.IME_ACTION_NEXT