Hide Keyboard When Tapping the Background of View

You must Login before you can answer or comment on any questions.

Hi all,

How to hide the keyboard when i tap somewhere except for the textfield?

1 Answer

on you view on which textfield is attached , add a 'click' event listener , and within that listener call textfield.blur();

view.add(textfield);// this is view on which your text filed is attached .
 
view.addEventListener("click",function(e){
 
textfield.blur(); // this will hide keyboard , if its opened before
});

— answered 7 months ago by Moiz Chhatriwala
answer permalink
1 Comment
  • Yeah, but text field also can be clicked, in view's "click" event listener you need check that text field did't get clicked.

    — commented 7 months ago by Ivan Škugor

Your Answer

Think you can help? Login to answer this question!