无法更改Android中自定义键盘的Enter键标签 [英] Cannot change Enter Key label for Custom keyboard in Android

查看:215
本文介绍了无法更改Android中自定义键盘的Enter键标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm designing a custom keyboard for Android. I want to have my custom label for ENTER key for some fields in my application. I used sample SoftKeyboard project for developing my keyboard. What I tried so far: 1- In one of my activities I have an EditText with the following attributes:

<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" />

如果我使用本机Android键盘,则在Enter键上显示登录",但是如果使用自定义键盘,则在以下语句中显示Enter键的默认值:

If I use Native Android keyboard it shows "Sign In" on my enter key but if I use my custom keyboard it shows the default value of enter key in the following statement:

如果有人可以帮助我解决此问题,我将不胜感激.

I would appreciate if someone can help me to solve this issue.

推荐答案

最后,我找到了解决方案.而不是传递int选项,我们必须传递EditorInfo属性.我们像波纹管一样传递它

Finally I found the solution. Instead of passing int options, we have to pass EditorInfo attribute. We pass it like bellow

@Override
    public void onStartInput(EditorInfo attribute, boolean restarting)
    {
        super.onStartInput(attribute, restarting);
         ...
        yourSoftKeyboard.setImeOptions(getResources(), attribute);
}

然后我们像下面这样实现setImeOptions:

Then we implement setImeOptions like bellow:

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;
        }
    }

这篇关于无法更改Android中自定义键盘的Enter键标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆