在onCreate()中,我设置:
searchView.setOnQueryTextListener(this);
searchView.setQuery("example text", false);在材料设计中,当我打开活动时,它会自动打开键盘(不点击SearchView)
但是当我在非物质设计的android设备上做同样的尝试时,幸运的是它不会自动打开键盘。
那么,如何在onCreate中禁用材料设计安卓设备中的键盘自动打开呢?
发布于 2015-08-13 17:51:05
添加此方法并在布局充气后在您的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);
}https://stackoverflow.com/questions/31994965
复制相似问题