Android的键盘没有出现

时间:2014-04-10 08:32:57

标签: android

我的Android键盘有问题。我有一个片段在屏幕顶部有一个EditText,下面有一个嵌套片段,它是一个QR扫描器。当我点击EditText写东西时,如果我没有长按一下设备的菜单按钮,键盘就不会出现。我正在尝试以编程方式显示我关注EditText但我无法做到。这是我的代码,提前谢谢。

EditText caja_edicion =(EditText) getActivity().findViewById(R.id.textcodigo);

            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(caja_edicion, InputMethodManager.SHOW_IMPLICIT);

1 个答案:

答案 0 :(得分:0)

尝试添加:

    caja_edicion.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(caja_edicion, InputMethodManager.SHOW_FORCED);
            } else {
                ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(caja_edicion.getWindowToken(), 0);
            }
        }
    });

我已经改变了,因为我处于片段状态但它不起作用,我不知道为什么:

final EditText caja_edicion =(EditText) getActivity().findViewById(R.id.textcodigo);

                caja_edicion.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(caja_edicion, InputMethodManager.SHOW_FORCED);
                        } else {
                            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(caja_edicion.getWindowToken(), 0);
                        }
                    }
                });
相关问题