0

I'm developing a soft keyboard for Android and I want the "DONE" key (KEYCODE_DONE) to be changed to "search, next" according to EditText ime options. How can I achieve that?

Myat Min Soe
  • 787
  • 8
  • 32
  • [Here](http://stackoverflow.com/questions/2568637/how-to-disable-next-button-on-a-edittext-software-keyboard-replace-with-done) is your answer. – Harin Mar 20 '15 at 08:39
  • 1
    I am developing a soft keyboard. I'm not create an app which contains EditText. – Myat Min Soe Mar 20 '15 at 09:17

2 Answers2

1

Finally I found it. Create a class which extends Keyboard and add the following method and call it from InputMethodService class.

@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
    Key key = new Key(res, parent, x, y, parser);
    if (key.codes[0] == -4) {
        mEnterKey = key;
    }
    return key;
}

private Key mEnterKey;
void setImeOptions(Resources res, int options) {
    if (mEnterKey == null) {
        return;
    }

    switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
        case EditorInfo.IME_ACTION_GO:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = "Go";
            break;
        case EditorInfo.IME_ACTION_NEXT:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = "Next";
            break;
        case EditorInfo.IME_ACTION_SEARCH:
            mEnterKey.icon = null;
            mEnterKey.iconPreview = null;
            mEnterKey.label = "Search";
            break;
        case EditorInfo.IME_ACTION_SEND:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = "Send";
            break;
        default:
            mEnterKey.icon = null;
            mEnterKey.iconPreview = null;
            mEnterKey.label = "Return";
            break;
    }
}
Myat Min Soe
  • 787
  • 8
  • 32
0

Check this link. There are different actions. select the one you required.

http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions

Abhinav Tyagi
  • 5,158
  • 3
  • 30
  • 60