gpt4 book ai didi

android - 处理键盘上的 Enter 和搜索键

转载 作者:行者123 更新时间:2023-11-29 19:06:19 24 4
gpt4 key购买 nike

嗨,如果有人对谷歌键盘有想法,当你在搜索中输入 url 时,它会显示搜索图标,当你输入短信或在 fb 或 EditText 等地方发表评论时,它会显示退格照片以供引用 This one show search button .所以下面的代码有效我想添加将 Enter 按钮与这些键一起输入,因为当我在 url 中使用此键盘输入时,我无法按 enter 键显示结果,它在 whatsapp 和其他应用程序中有效,但在浏览器中无效。

this one show backspace

 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 区域中输入时向其添加输入/搜索键

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

关于android - 处理键盘上的 Enter 和搜索键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47099929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com