Android自定义键盘 - 如何获取浏览器InputType?

时间:2015-07-01 10:54:52

标签: android android-softkeyboard

我正在尝试使用键盘为每种输入类型(如简单文本,数字,电子邮件,URL地址等)制作自定义Android键盘(最小API 16)。我不明白的是如何获取浏览器URL TextEditor InputType,以便我可以使用“访问”按钮制作键盘。

@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
    super.onStartInput(attribute, restarting);

    switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
        case InputType.TYPE_CLASS_NUMBER:
        case InputType.TYPE_CLASS_DATETIME:
        case InputType.TYPE_CLASS_PHONE:
            mCurKeyboard = symKeyboard_1;
            break;
        case InputType.TYPE_TEXT_VARIATION_URI:
        case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT:
        case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
        case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT:
        case InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS:
        case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
            mCurKeyboard = webKeyboard;
            Log.d("debug", "web keyboard");
            break;
        case InputType.TYPE_CLASS_TEXT:
            mCurKeyboard = myKeyboard;
            Log.d("debug", "text");
            break;
        default:
            mCurKeyboard = myKeyboard;
            Log.d("debug", "default");
            break;
    }
}

但我仍然将InputType.TYPE_CLASS_TEXT作为InputType。

我想我已经尝试了几乎所有的InputType,但没有一个可以确定我何时输入了URL文本框。我需要一个解决方案来查找URL TextEditor的输入类型。

顺便说一句:如何通过传递给Access的{​​{1}}对浏览器执行GoKeyEvent操作?

稍后编辑。溶液

getCurrentInputConnection().sendKeyEvent()

@ ray20表示处理“Access”,“GO”动作的答案,这是针对其他编辑动作的:

@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
    super.onStartInput(attribute, restarting);

    switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
        case InputType.TYPE_CLASS_NUMBER:
        case InputType.TYPE_CLASS_DATETIME:
        case InputType.TYPE_CLASS_PHONE:
            currentKeyboard = numericKeyboard;
            break;
        case InputType.TYPE_CLASS_TEXT:
            int webInputType = attribute.inputType & InputType.TYPE_MASK_VARIATION;

            if (webInputType == InputType.TYPE_TEXT_VARIATION_URI ||
                    webInputType == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT ||
                    webInputType == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                    || webInputType == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS) {
                currentKeyboard = webKeyboard;
            }else{
                currentKeyboard = latinKeyboard;
            }
            break;
        default:
            currentKeyboard = latinKeyboard;
            break;
    }
}

1 个答案:

答案 0 :(得分:0)

执行GO动作

getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_GO);