hide virtual keyboard in android?

后端 未结 4 830
情深已故
情深已故 2021-01-25 08:08

Hi i won\'t want to show virtual keyboard even user touch the editText field.

相关标签:
4条回答
  • 2021-01-25 08:43

    Have you tried adding android:configChanges="keyboard|keyboardHidden" into your activity?

    e.g.:

    <activity android:name=".MyApp" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden">
    

    Not sure if it applies to the onscreen keyboard as well as a physical one.

    Also you can mess with the On Screen Keyboard using the InputMethodManager, for example to hide it you could use:

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);
    
    0 讨论(0)
  • 2021-01-25 08:43

    try this

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        boolean ret = super.dispatchTouchEvent(event);
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);  
        return ret;
    }
    

    or

    editText.setOnTouchListener(new View.OnTouchListener() {
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mCurretnView.getWindowToken(), 0);  
            return false;
        }
    });
    
    0 讨论(0)
  • 2021-01-25 08:46

    As in this question use:

    EditText edtView=(EditText)findViewById(R.id.editTextConvertValue);
    edtView.setInputType(0);
    
    0 讨论(0)
  • 2021-01-25 08:59
    InputMethodManager inputMethodManager = (InputMethodManager) currentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (isShow) {
        if (currentActivity.getCurrentFocus() == null) {
            inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        } else {
            inputMethodManager.showSoftInput(currentActivity.getCurrentFocus(), InputMethodManager.SHOW_FORCED);    
        }
    
    } else {
        if (currentActivity.getCurrentFocus() == null) {
            inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0);
        } else {
            inputMethodManager.hideSoftInputFromInputMethod(currentActivity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);    
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题