5

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 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!

Han
  • 620
  • 2
  • 10
  • 22
  • check out this http://stackoverflow.com/questions/7289335/soft-keyboard-shows-up-on-edittext-focus-only-once/7291121#7291121 – Lalit Poptani Oct 05 '11 at 18:12
  • thx but I am having a different issue there... I want to hide the keyboard from the very beginning and prevent it from popping up no matter what I do – Han Oct 05 '11 at 18:32

1 Answers1

8

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;
}
Han
  • 620
  • 2
  • 10
  • 22