Handling Enter and search key on the keyboard
嗨,我想如果有人有关于谷歌键盘的想法,当你在搜索中输入网址时显示搜索图标,当你输入短信或评论那里像fb或EditText这样的地方时,它会显示Backspace照片以供参考。
所以下面的代码正在工作,我想添加
与这些键一起输入按钮,当我在网址中输入此键盘时,我无法按Enter键显示结果在whatsapp和其他应用程序中工作但不在浏览器中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 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区域时添加输入/搜索键
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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; } |
我不得不创建两个不同的键盘xml,一个带有输入按钮,另一个带有退格键。 我必须输入带有退格按钮apear的edittext键盘,当在搜索栏中输入然后输入按钮apear键盘。
1 2 3 4 5 6 7 8 9 10 | 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; } }); |