java Android:无法弄清楚如何使用 setImeActionLabel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1538331/
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-10-29 17:00:03  来源:igfitidea点击:

Android: Can't figure how to use setImeActionLabel

javaandroidandroid-edittext

提问by Felix

What I want to do is change the default "Done" label that appears in the virtual keyboard. Here's what I've tried without any luck:

我想要做的是更改虚拟键盘中显示的默认“完成”标签。这是我在没有任何运气的情况下尝试过的:

mSearchInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
mSearchInput.setImeActionLabel(getString(R.string.search_action_label), EditorInfo.IME_ACTION_DONE);

I amable, however, to handle a click on that button, with this:

能干,但是,处理该按钮的点击,这一点:

mSearchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            performSearch();
            return true;
        }
        return false;
    }
});

I'm clueless as to how I can change the label on that button at the moment.

我目前不知道如何更改该按钮上的标签。

回答by mernen

The imeActionLabelsets the label for the button that appears on the top right on full screen IME mode (i.e., when your phone is in landscape). If you want to change the button to the bottom right of the keyboard, you can pass certain flags to imeOptions.

imeActionLabel套标签上的全屏IME模式右上方出现的按钮(即,当您的手机处于横向)。如果要更改键盘右下角的按钮,可以将某些标志传递给imeOptions

As far as I know, for that button you're limited to a certain set of actions (see herefor a full list of supported flags), but since you seem to want a search button, all you have to do is to slightly adjust your first line and use IME_ACTION_SEARCH:

据我所知,对于该按钮,您仅限于一组特定的操作(请参阅此处获取受支持标志的完整列表),但由于您似乎想要一个搜索按钮,您所要做的就是稍微调整一下您的第一行并使用IME_ACTION_SEARCH

mSearchInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

Mind you, the exact appearance of that button will depend on the input method. The default Android keyboard shows a magnifier for the search flag, while the Touch Input (HTC's keyboard) seems completely unaware of that flag, still showing a return button.

请注意,该按钮的确切外观取决于输入法。默认的 Android 键盘显示搜索标志的放大镜,而触摸输入(HTC 的键盘)似乎完全不知道该标志,仍然显示返回按钮。