android更改键盘布局,如何通过按Shift键更改android的键盘布局

我目前正在自己​​的实现Input Method Editor (IME)或可以在Android中调用Softkeyboard我已阅读creating an input method我已经下载the SoftKeyboard sample code provided as part of the SDK。我有以下代码sample Softkeyboard:如何通过按Shift键更改android的键盘布局

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

updateCandidates();

} else {

getCurrentInputConnection().commitText(

String.valueOf((char) primaryCode), 1);

}

}

上面给出的代码工作正常,但是当我点击的关键是:

android:keyWidth="15%p" android:isModifier="true"

android:isSticky="true" android:keyEdgeFlags="left"/>

这就好比Shift键,将其转换键为大写我不“知道如何表达我的下一个键时,该按键被按下/压,以下是例外的Logcat:

765e9a7cf5b3db670332883f7580dfd6.png

我已经查明,这可能在这个地方,我们处理Shift键出现:

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

}

}

现在我没有任何想法如何摆脱上述异常,并得到我的代码工作。请解决这个问题!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值