显示“完成”软键盘上的键

发布于 2024-12-18 15:51:00 字数 1239 浏览 9 评论 0原文

在我的应用程序中将文本输入到 EditText 时,我需要软键盘来显示“完成”键。在 Android 2.1 设备上会显示“完成”按钮,但在 2.3 或更高版本上不会显示。

这是我使用的代码:

    e.setImeOptions(EditorInfo.IME_ACTION_DONE);

    e.setOnEditorActionListener(
            new EditText.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                            actionId == EditorInfo.IME_ACTION_DONE ||
                            event.getAction() == KeyEvent.ACTION_DOWN &&
                            event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                        Toast.makeText(getBaseContext(), e.getText().toString(), Toast.LENGTH_SHORT).show();

                        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(e.getWindowToken(), 0);

                        return true;
                    }
                    return false;
                }
            });

我使用的是 Android 版本 2.3.4 的三星设备。

编辑文本的屏幕截图:

在此处输入图像描述

I need the softkeyboard to display the 'Done' key when inputting text into an EditText in my application. On an Android 2.1 device the 'Done' button is displayed, but not on 2.3 or it higher.

This is the code I use:

    e.setImeOptions(EditorInfo.IME_ACTION_DONE);

    e.setOnEditorActionListener(
            new EditText.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                            actionId == EditorInfo.IME_ACTION_DONE ||
                            event.getAction() == KeyEvent.ACTION_DOWN &&
                            event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                        Toast.makeText(getBaseContext(), e.getText().toString(), Toast.LENGTH_SHORT).show();

                        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(e.getWindowToken(), 0);

                        return true;
                    }
                    return false;
                }
            });

I am using a samsung device with Android version 2.3.4.

Screenshort of the edittext:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这不是 Android 版本的问题,而是您设备使用的 IME 的问题。三星(我认为还有一些 HTC)IME 永远不会将字母更改为“Done”或“Next”或“Go”。

It is not Android version's fault, but the IME your device use. Samsung (and some of HTC, I think) IME never change the letter to "Done" or "Next" or "Go".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文