【问题标题】:android soft keyboard capitalisationandroid软键盘大小写
【发布时间】:2013-02-17 05:56:00
【问题描述】:

我正在尝试将 Android 示例软键盘设置为首字母大写。这是键盘的正常行为,但我不知道该怎么做((

【问题讨论】:

    标签: android keyboard capitalization


    【解决方案1】:

    回答肯定​​有点晚了,但其他人可能需要这个。

    要手动大写键盘,您必须使用所需的转换模式调用 KeyboardViewsetShifted (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);
        }
    }
    

    【讨论】:

    • 太棒了,你拯救了我的一天
    【解决方案2】:

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

    【讨论】:

    • 我开发了键盘,textView可能来自不同的应用程序。我需要在键盘中设置此逻辑以将此类 textViews 中的字母大写。
    猜你喜欢
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多