无法更改Android中自定义键盘的Enter键标签

无法更改Android中自定义键盘的Enter键标签,android,android-softkeyboard,custom-keyboard,imeoptions,Android,Android Softkeyboard,Custom Keyboard,Imeoptions,我正在为Android设计一个定制键盘。我想为我的应用程序中的某些字段的ENTER键设置自定义标签。我使用示例软键盘项目来开发我的键盘。 到目前为止,我尝试的是: 1-在我的一个活动中,我有一个具有以下属性的EditText: <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" androi

我正在为Android设计一个定制键盘。我想为我的应用程序中的某些字段的ENTER键设置自定义标签。我使用示例软键盘项目来开发我的键盘。 到目前为止,我尝试的是: 1-在我的一个活动中,我有一个具有以下属性的EditText:

<EditText
    android:id="@+id/password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:imeActionId="@+id/action_sign_in"
    android:imeActionLabel="@string/sign_in"

    android:inputType="textPassword" />

如果有人能帮我解决这个问题,我将不胜感激。

我终于找到了解决方案。我们必须传递EditorInfo属性,而不是传递int选项。我们像吼叫一样通过它

@Override
    public void onStartInput(EditorInfo attribute, boolean restarting)
    {
        super.onStartInput(attribute, restarting);
         ...
        yourSoftKeyboard.setImeOptions(getResources(), attribute);
}
然后,我们实现如下设置选项:

void setImeOptions(Resources res, EditorInfo ei)
    {
        if (enterKey == null)
        {
            return;
        }

        switch (ei.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION))
        {
            case EditorInfo.IME_ACTION_SEND:
                enterKey.iconPreview = null;
                enterKey.icon = null;
                enterKey.label ="Send";
                break;
            case EditorInfo.IME_ACTION_GO:
                enterKey.iconPreview = null;
                enterKey.icon = null;
                enterKey.label ="Go";
                break;
            case EditorInfo.IME_ACTION_NEXT:
                enterKey.iconPreview = null;
                enterKey.icon = null;
                enterKey.label = "Next";
                break;
            case EditorInfo.IME_ACTION_SEARCH:
                enterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
                enterKey.label = null;
                break;
            default:
                enterKey.iconPreview = null;
                enterKey.label = "Enter";
                enterKey.icon = null;
                break;
        }

        if (ei.actionLabel != null)
        {
            enterKey.iconPreview = null;
            enterKey.icon = null;
            enterKey.label = ei.actionLabel;
        }
    }
void setImeOptions(Resources res, EditorInfo ei)
    {
        if (enterKey == null)
        {
            return;
        }

        switch (ei.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION))
        {
            case EditorInfo.IME_ACTION_SEND:
                enterKey.iconPreview = null;
                enterKey.icon = null;
                enterKey.label ="Send";
                break;
            case EditorInfo.IME_ACTION_GO:
                enterKey.iconPreview = null;
                enterKey.icon = null;
                enterKey.label ="Go";
                break;
            case EditorInfo.IME_ACTION_NEXT:
                enterKey.iconPreview = null;
                enterKey.icon = null;
                enterKey.label = "Next";
                break;
            case EditorInfo.IME_ACTION_SEARCH:
                enterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
                enterKey.label = null;
                break;
            default:
                enterKey.iconPreview = null;
                enterKey.label = "Enter";
                enterKey.icon = null;
                break;
        }

        if (ei.actionLabel != null)
        {
            enterKey.iconPreview = null;
            enterKey.icon = null;
            enterKey.label = ei.actionLabel;
        }
    }