【发布时间】:2013-02-17 05:56:00
【问题描述】:
我正在尝试将 Android 示例软键盘设置为首字母大写。这是键盘的正常行为,但我不知道该怎么做((
【问题讨论】:
标签: android keyboard capitalization
我正在尝试将 Android 示例软键盘设置为首字母大写。这是键盘的正常行为,但我不知道该怎么做((
【问题讨论】:
标签: android keyboard capitalization
回答肯定有点晚了,但其他人可能需要这个。
要手动大写键盘,您必须使用所需的转换模式调用 KeyboardView 的 setShifted (boolean shifted) 方法。
这是一个例子:
private KeyboardView mInputView;
...
mInputView.setShifted(true);
但最好让软键盘通过检查文本编辑器的属性来决定其大小写模式。例如,电子邮件通常使用小写字母输入。
如果您查看此示例here,它有一个名为updateShiftKeyState(EditorInfo attr) 的方法,用于根据将在其中键入文本的文本编辑器的初始属性自动设置大写模式:
/**
* 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);
}
}
【讨论】:
只需为布局中的 textview 设置 android:capitalize xml 属性。检查属性here的可能值
【讨论】: