Search code examples
androidandroid-edittextandroid-keypad

Disabling the soft keyboard


I need to disable soft keyboard, and enable only hard one, so I created this kind of edittext, It works really good, but on some htc phones this type of edittext disabling multiline statement(don't know how it works).

public class NoImeEditText extends EditText {
    public NoImeEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean onCheckIsTextEditor() {
        return false;
    }
}

another way I using this kind of code and it doesn't work.

    keyboardText.setShowSoftInputOnFocus(false);


    InputMethodManager imm = (InputMethodManager)getMainActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null)
        imm.hideSoftInputFromWindow(keyboardText.getWindowToken(), 0); 

Solution

  • This might works,

       @Override
        protected void onCreate(Bundle savedInstanceState) {
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
    

    This will hide soft keyboard.