处理键盘上的 Enter 和搜索键

Handling Enter and search key on the keyboard

你好,如果有人对 google 键盘有想法,当你在搜索中输入 url 时,它会显示搜索图标,当你输入短信或在 fb 或 EditText 等地方发表评论时,它会显示搜索图标显示 Backspace 照片以供参考。 所以下面的代码有效我想添加 与这些键一起输入按钮,因为当我在 url 中使用此键盘输入时,我无法按回车键显示结果它在 whatsapp 和其他应用程序中有效,但在浏览器中无效。

 public void onKey(int primaryCode, int[] keyCodes) {
    this.previousWord = "";
    if (isWordSeparator(primaryCode) && this.mComposing.length() > 0) {
        this.previousWord = this.mComposing.toString();
        commitTyped(getCurrentInputConnection());
    }
    playClick(primaryCode);
    Keyboard current;
    if (primaryCode == -5) {
        handleBackspace();
    } else if (primaryCode == -1) {
        handleShift();
    } else if (primaryCode == -4) {
        handleClose();
    }else if (primaryCode == -2) {
        if (this.kv.getKeyboard() == this.symbols) {
            current = this.keyboard;
        } else {
            current = this.symbols;
        }
        this.kv.setKeyboard(current);
        if (current == this.symbols) {
            current.setShifted(false);
        }
    } else if (primaryCode == -6) {
        if (this.kv.getKeyboard() == this.eng_keyboard) {
            current = this.keyboard;
        } else {
            current = this.eng_keyboard;
        }
        this.kv.setKeyboard(current);
    }else if (primaryCode == -10) {
        if (this.kv.getKeyboard() == this.keyboard) {
            current = this.eng_keyboard;
        } else {
            current = this.keyboard;
        }
        this.kv.setKeyboard(current);
    }else {
        handleCharacter(primaryCode, keyCodes);
    }
}

这些键有效 我想在 url 区域输入时添加 enter/search 键

public void swipeDown() {
    handleClose();
}

public void swipeLeft() {
    pickSuggestionManually(1);
}

public void swipeRight() {
    handleBackspace();
}

public void swipeUp() {
}

private void handleClose() {
    requestHideSelf(0);
    this.mComposing = new StringBuilder();
    setSuggestions(null, false, false);
    updateCandidates();
    this.kv.closing();
}

private void handleCharacter(int primaryCode, int[] keyCodes) {
    if (isInputViewShown() && isInputViewShown() && this.kv.isShifted()) {
        primaryCode = Character.toUpperCase(primaryCode);
    }
    if (isAlphabet(primaryCode) && this.mPredictionOn) {
        this.mComposing.append((char) primaryCode);
        getCurrentInputConnection().setComposingText(this.mComposing, 1);
        updateShiftKeyState(getCurrentInputEditorInfo());
        updateCandidates();
        return;
    }
    getCurrentInputConnection().commitText(String.valueOf((char) primaryCode), 1);
}

private void handleShift() {
    if (this.kv != null && this.eng_keyboard == this.kv.getKeyboard()) {
        checkToggleCapsLock();
        KeyboardView keyboardView = this.kv;
        boolean z = this.mCapsLock || !this.kv.isShifted();
        keyboardView.setShifted(z);
    }
}

private void checkToggleCapsLock() {
    long now = System.currentTimeMillis();
    if (this.mLastShiftTime + 800 > now) {
        this.mCapsLock = !this.mCapsLock;
        this.mLastShiftTime = 0;
        return;
    }
    this.mLastShiftTime = now;
}
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            performSearch();
            return true;
        }
        return false;
    }
});

我必须创建两个不同的键盘 xml 一个带有回车键,另一个带有退格键。我必须输入带有退格键的 edittext 键盘,当输入搜索栏时,然后输入带有回车键的键盘。