Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 879
Han Avatar asked Oct 05 '11 18:10

Han


1 Answers

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;
}
like image 157
Han Avatar answered Sep 30 '22 20:09

Han