Null pointer error with hideSoftInputFromWindow

网友投稿 633 2022-11-25

Null pointer error with hideSoftInputFromWindow

Null pointer error with hideSoftInputFromWindow

1.

anyView.getWindowToken()

2

If you want to hide keyboard when touching in the screen, use the below code

@Overridepublic boolean onTouchEvent(MotionEvent event) { InputMethodManager imm = (InputMethodManager)this.getSystemService(Context. INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getRootView().getWindowToken(), 0); return true;}

If you want to do this in specific view (EditText)

public void hideKeyBoard(EditText edt) { InputMethodManager imm = (InputMethodManager)this.getSystemService(Context. INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edt.getWindowToken(), 0);}

还有几种方法

​​https://stackoverflow.com/questions/19069448/null-pointer-error-with-hidesoftinputfromwindow​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Android TextView之空格占位法
下一篇:选择自定义铃声
相关文章

 发表评论

暂时没有评论,来抢沙发吧~