如何将焦点从WhatsApp编辑字段更改为在自定义键盘中实现的自定义编辑字段?

时间:2019-05-31 06:09:16

标签: java android keyboard

我为贴纸应用创建了自定义键盘。它具有搜索贴纸并在WhatsApp,Facebook等上共享的功能。 但是我的问题是,我无法在键盘内将焦点从WhatsApp编辑字段更改为自定义edittext。 当前,当我尝试触摸键盘中实现的编辑文本并在其中写入一些文本时,它会自动在默认的WhatsApp编辑字段中进行编辑,而不会在自定义编辑文本中进行编辑。

任何解决方案...

这是我的代码。

keyboard_view.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener() {
        @Override
        public void onPress(int i) {
        }

        @Override
        public void onRelease(int i) {

        }

        @Override
        public void onKey(int primaryCode, int[] ints) {
            InputConnection ic = getCurrentInputConnection();
            playClick(primaryCode);
            switch (primaryCode) {
                case Keyboard.KEYCODE_DELETE:
                    getCurrentInputConnection().sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
                    break;
                case Keyboard.KEYCODE_SHIFT:
                    caps = !caps;
                    keyboard.setShifted(caps);
                    keyboard_view.invalidateAllKeys();
                    break;
                case android.inputmethodservice.Keyboard.KEYCODE_DONE:
                    if (isSearched){
                        searchQuery();
                        frame_contain.setVisibility(View.GONE);
                        frame_container_search.setVisibility(View.VISIBLE);
                        keyboard_view.setVisibility(View.GONE);
                        search_view_items.setVisibility(View.VISIBLE);
                        callAdapterForSearchedStickers();
                        isSearched = false;
                        break;
                    }else {
                        frame_contain.setVisibility(View.GONE);
                        frame_container_search.setVisibility(View.GONE);
                        keyboard_view.setVisibility(View.VISIBLE);
                        search_view_items.setVisibility(View.GONE);
                        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
                        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
                        break;
                    }


                case Keyboard.KEYCODE_MODE_CHANGE:
                    if (KeyboardService.afroemojiEnabled(getApplicationContext())) {
                        InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showInputMethodPicker();
                    } else {
                        startActivity(new Intent("android.settings.INPUT_METHOD_SETTINGS"));
                    }
                    break;
                case -100:
                    mainBoard.setBackgroundColor(Color.parseColor("#ffffff"));
                    ic.deleteSurroundingText(1, 0);
                    packNameLabel.setVisibility(View.VISIBLE);

                    stickerView.setVisibility(View.VISIBLE);
                    keyboard_view.setVisibility(View.GONE);
                    frame_contain.setVisibility(View.VISIBLE);

                    share_layout.setVisibility(View.VISIBLE);
                    break;
                case 82:

                    keyboard_view.setKeyboard(numerice_keyboared);
                    keyboard_view.setPreviewEnabled(false);
                    break;
                case 23:

                    keyboard_view.setKeyboard(keyboard);
                    keyboard_view.setPreviewEnabled(false);
                    break;
                default:
                    char code = (char) primaryCode;
                    if (Character.isLetter(code) && caps) {
                        code = Character.toUpperCase(code);
                    }
                    ic.commitText(String.valueOf(code), 1);
            }
        }

        @Override
        public void onText(CharSequence charSequence) {

        }

        @Override
        public void swipeLeft() {

        }

        @Override
        public void swipeRight() {

        }

        @Override
        public void swipeDown() {

        }

        @Override
        public void swipeUp() {

        }
    });

0 个答案:

没有答案