android点击editText后尝试打开键盘

时间:2014-04-01 12:01:45

标签: android android-studio

我试图打开键盘然后进入logcat

  

682-682 / com.android.inputmethod.latin V / InputMethodService:   onEvaluateInputViewShown:config.hardKeyboardHidden = 1

我的代码:

   InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);

    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
            } else {

            }
        }
    });

谢谢!

2 个答案:

答案 0 :(得分:1)

试试这个,

在活动顶部声明此内容

InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE);

并且在edittext中使用它,

imm.showSoftInput(editText, 0);

或者你也可以试试这个,

InputMethodManager m = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  if(m != null){
      m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
   } 

答案 1 :(得分:1)

试试这个:

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {

            return true;
        }
        return false;
    }

});