0

我试图让用户在键盘之间切换,例如从 Qwerty 切换到笑脸键盘。我无法理解用户如何通过使用 shift 或在 iPhone 上通过地球按钮从 Qwerty 切换到表情符号的概念。我对如何编写实际的“开关”感到困惑。我在软键盘 SDK 示例中找到了以下代码,我想知道这是否是切换发生的方式。

private void handleShift() {
        if (mInputView == null) {
            return;
        }

        Keyboard currentKeyboard = mInputView.getKeyboard();
        if (mQwertyKeyboard == currentKeyboard) {
            // Alphabet keyboard
            checkToggleCapsLock();
            mInputView.setShifted(mCapsLock || !mInputView.isShifted());
        } 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);
        }
    }

我再次尝试初始化一个开关,允许用户按下 shift 按钮并切换到表情符号,一旦选择切换回 qwerty 发送......

4

1 回答 1

0

示例软键盘被编码为在按下 shift 键时从符号键盘更改为符号移位键盘。要将表情符号键盘布局添加到旋转中,请将发布的代码更改为以下内容:

private void handleShift() {
    if (mInputView == null) {
        return;
    }

    Keyboard currentKeyboard = mInputView.getKeyboard();
    if (mQwertyKeyboard == currentKeyboard) {
        // Alphabet keyboard
        checkToggleCapsLock();
        mInputView.setShifted(mCapsLock || !mInputView.isShifted());
    } else if (currentKeyboard == mSymbolsKeyboard) {
        mSymbolsKeyboard.setShifted(true);
        mInputView.setKeyboard(mSymbolsShiftedKeyboard);
        mSymbolsShiftedKeyboard.setShifted(true);
    } else if (currentKeyboard == mSymbolsShiftedKeyboard) {
        mSymbolsShiftedKeyboard.setShifted(false);
        mInputView.setKeyboard(mEmoticonKeyboard);
        mSymbolsKeyboard.setShifted(false);
    } else if (currentKeyboard == mEmoticonKeyboard) {
        mInputView.setKeyboard(mSymbolsKeyboard);
    }

}
于 2012-04-12T03:17:51.460 回答