android软键盘大小写

时间:2013-02-17 05:56:00

标签: android keyboard capitalization

我正在尝试设置Android示例软键盘来制作句子首字母的第一个字母。这是键盘的正常行为,但我不知道如何做到这一点((

2 个答案:

答案 0 :(得分:1)

要回答有点迟,但其他人可能需要这个。

要手动将键盘大写,您必须使用所需的移位模式调用KeyboardView setShifted (boolean shifted)方法。

以下是一个例子:

private KeyboardView mInputView;
...
mInputView.setShifted(true);

但是,如果通过检查文本编辑器的属性让SoftKeyboard决定其大小写模式,那就更好了。例如,电子邮件通常使用小写字母键入。 如果您查看此示例here,它会有一个名为updateShiftKeyState(EditorInfo attr)的方法,该方法用于根据文本编辑器的初始属性自动设置大小写模式,其中将输入文本: / p>

/**
 * Helper to update the shift state of our keyboard based on the initial
 * editor state.
 */
private void updateShiftKeyState(EditorInfo attr) {
    if (attr != null 
            && mInputView != null && mQwertyKeyboard == mInputView.getKeyboard()) {
        int caps = 0;
        EditorInfo ei = getCurrentInputEditorInfo();
        if (ei != null && ei.inputType != InputType.TYPE_NULL) {
            caps = getCurrentInputConnection().getCursorCapsMode(attr.inputType);
        }
        mInputView.setShifted(mCapsLock || caps != 0);
    }
}

答案 1 :(得分:0)

只需在布局中为textview设置android:capitalize xml属性即可。检查属性here

的可能值