键盘edittext时得到专注?

这个问题在这里已经有了答案:

  • Android:在焦点位于EditText 19答案时自动显示软键盘

  • 通过InputMethodManager您可以显示和隐藏软键盘。 使用toggleSoftInput()方法在EditText获取焦点时显示软键盘,并在EditText失去焦点时使用hideSoftInputFromWindow()隐藏键盘,如下所示...

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    
    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean isFocused) {
    
            if (isFocused) {
    
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
            } else {
    
                imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0); 
            }
        }
    });
    

    试用这些代码..

    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
    
    链接地址: http://www.djcxy.com/p/93379.html

    上一篇: keyboard when edittext is get focused?

    下一篇: Can I use the soft keyboard without an EditText?