【问题标题】:SearchView Disable auto keyboard Material DesignSearchView 禁用自动键盘 Material Design
【发布时间】:2015-11-06 19:38:49
【问题描述】:
在onCreate()我设置:
searchView.setOnQueryTextListener(this);
searchView.setQuery("example text", false);
在 Material Design 中,当我打开 Activity 时,它会自动打开键盘(无需点击 SearchView)
但是,当我在非 Material Design android 设备上尝试相同时,幸运的是它不会自动打开键盘。
那么如何在 Material Design android 设备上禁用 onCreate 中自动打开键盘?
【问题讨论】:
标签:
android
keyboard
android-5.0-lollipop
material-design
searchview
【解决方案1】:
添加此方法并在布局膨胀后在 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);
}