在片段被选中时展开searchview,请求专注于searchview但隐藏软键盘。
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.barcode,menu);
MenuItem scan = menu.findItem(R.id.scanbarcode);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuItem scan = menu.findItem(R.id.scanbarcode);
mBarcode = (android.support.v7.widget.SearchView) scan.getActionView();
mBarcode.setQueryHint(getString(R.string.scanb));
scan.expandActionView();
mBarcode.setOnQueryTextListener(this);
}
答案 0 :(得分:0)
将此内容写入清单文件中的活动
android:windowSoftInputMode="stateHidden|adjustResize"
并在您的片段中使用
searchTditText.requestFocus();
答案 1 :(得分:0)
调用此方法隐藏软键盘。
public static void hideSoftKeyboard(Context context, View view) {
if (view != null) {
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
答案 2 :(得分:0)
检查此代码:
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}