[英]SearchView Disable auto keyboard Material Design
在onCreate()
我设置了:
searchView.setOnQueryTextListener(this);
searchView.setQuery("example text", false);
在Material Design中,当我打开活动时,它会自动打开键盘(无需单击SearchView)
但是,当我在非材料设计的android设备上尝试相同操作时,幸运的是不会自动打开键盘。
那么如何在Material Design android设备的onCreate
禁用自动打开键盘的功能呢?
添加此方法并在布局放大后在onCreate中调用它。
private void closeKeyboard() {
View currentFocus = this.getCurrentFocus();
if (currentFocus!=null){
android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager)this.getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.