How do I prevent the software keyboard from popping up?
I have my own keypad in my application so I want to hide the software keyboard all the time(in specific activities & dialogs). I experimented with two options:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
This开发者_如何学C code prevent the keyboard from popping up at the beginning, but when I click on the textbox the keyboard still pops.
InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
This code hide the keyboard, but it doesn't prevent the keyboard from popping up.
PLEASE HELP!
Finally figured out!
I used
public void supressKeyboard() {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
for the activities where I want to suppress the keyboard(you can put it in a general activity where all other activities inherit from)
But this won't prevent the keyboard from popping up when you click on the EditText textbox. What I did is I consumed the onTouch event for the text box:
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
精彩评论