如何通过按Shift键更改android中的键盘布局
我目前正在开发自己的如何通过按Shift键更改android中的键盘布局,android,android-softkeyboard,android-input-method,Android,Android Softkeyboard,Android Input Method,我目前正在开发自己的输入法编辑器(IME),或者在Android中可以称为软键盘,我已经阅读并下载了作为SDK的一部分提供的软键盘示例代码。我有以下代码来自: 现在我不知道如何摆脱上面提到的异常,并让我的代码正常工作。请解决这个问题 对于您的问题,可能还有其他一些解决方案,但我已经做了一个技巧,并得出了以下结论: 步骤1您必须删除对方法的所有调用updateShiftKeyState(getCurrentInputEditor())在您的代码中,例如: private void handleCh
输入法编辑器(IME)
,或者在Android中可以称为软键盘
,我已经阅读并下载了作为SDK的一部分提供的软键盘示例代码。我有以下代码来自:
现在我不知道如何摆脱上面提到的异常,并让我的代码正常工作。请解决这个问题 对于您的问题,可能还有其他一些解决方案,但我已经做了一个技巧,并得出了以下结论:
步骤1您必须删除对方法的所有调用updateShiftKeyState(getCurrentInputEditor())代码>在您的代码中,例如:
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
/**
* Swapping here with my desired unicode character
* */
if (primaryCode >= 97 && primaryCode <= 122 ) {
mComposing.append(Swap.swapLetters(primaryCode));
}else{
mComposing.append((char) primaryCode);
}
getCurrentInputConnection().setComposingText(mComposing, 1);
//updateShiftKeyState(getCurrentInputEditorInfo()); // you can delete this method from your class and clean-up all the occurances of that
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}}
仅此而已,希望这对您有用…您的问题可能还有其他解决方案,但我已经完成了一个技巧,并得出以下结论:
步骤1您必须删除对方法的所有调用updateShiftKeyState(getCurrentInputEditor())代码>在您的代码中,例如:
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
/**
* Swapping here with my desired unicode character
* */
if (primaryCode >= 97 && primaryCode <= 122 ) {
mComposing.append(Swap.swapLetters(primaryCode));
}else{
mComposing.append((char) primaryCode);
}
getCurrentInputConnection().setComposingText(mComposing, 1);
//updateShiftKeyState(getCurrentInputEditorInfo()); // you can delete this method from your class and clean-up all the occurances of that
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}}
就这些,希望这对你有用
private void handleShift() {
if (mInputView == null) {
return;
}
Keyboard currentKeyboard = mInputView.getKeyboard();
if (mQwertyKeyboard == currentKeyboard) {
// Alphabet keyboard
checkToggleCapsLock();
mInputView.setKeyboard(mSindhi);
} else if (currentKeyboard == mSymbolsKeyboard) {
mSymbolsKeyboard.setShifted(true);
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
mSymbolsShiftedKeyboard.setShifted(true);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mSymbolsShiftedKeyboard.setShifted(false);
mInputView.setKeyboard(mSymbolsKeyboard);
mSymbolsKeyboard.setShifted(false);
}
}
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
/**
* Swapping here with my desired unicode character
* */
if (primaryCode >= 97 && primaryCode <= 122 ) {
mComposing.append(Swap.swapLetters(primaryCode));
}else{
mComposing.append((char) primaryCode);
}
getCurrentInputConnection().setComposingText(mComposing, 1);
//updateShiftKeyState(getCurrentInputEditorInfo()); // you can delete this method from your class and clean-up all the occurances of that
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}}
private void handleShift() {
if (mInputView == null) {
return;
}
Keyboard currentKeyboard = mInputView.getKeyboard();
if (mQwertyKeyboard == currentKeyboard) {
mInputView.setKeyboard(mSindhi);
} else if (currentKeyboard == mSymbolsKeyboard) {
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mInputView.setKeyboard(mSymbolsKeyboard);
}
}