i want to hide the soft keyboard when i click out side of editbox in a screen. how can i do this?
I got a good solution.I know its too late but when searching most of times getting this link as first link. so it may be helpful for others. If you click on any text/button it will hide the softkeyboard which is already visible.
date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Hide soft keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
// here i am showing the Date Dialog. one can proceed with their functionality
//show date picker dialog
showDialog(Date_DIALOG_ID);
}
});
public boolean OutsideTouchEvent(MotionEvent m_event) {
View v = getCurrentFocus();
boolean value = super.dispatchTouchEvent(m_event);
View w = getCurrentFocus();
int scrcoords[] = new int[2];
w.getLocationOnScreen(scrcoords);
float x = m_event.getRawX() + w.getLeft() - scrcoords[0];
float y = m_event.getRawY() + w.getTop() - scrcoords[1];
if (m_event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom()) ) {
InputMethodManager inputMethodManager = (InputMethodManager) YourActivity.this.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(YourActivity.this.getCurrentFocus().getWindowToken(), 0);
}
return value;
}
Just set the input type to null like that
editText.setInputType(InputType.TYPE_NULL);
set inputType to zero for edit text
editText.setInputType(0);
it's work for me