<EditText android:id="@+id/ed_search" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:layout_weight="1" android:background="@color/background_gray" android:drawableLeft="@mipmap/ic_search" android:drawableRight="@mipmap/ic_mic" android:drawablePadding="6dp" android:hint="请输入网点名称" android:imeActionId="84" android:imeActionLabel="search" android:imeOptions="actionSearch" android:maxLines="1" android:paddingLeft="6dp" android:paddingRight="6dp" android:singleLine="true" android:textSize="14sp" />
ed_search_input.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (!b) { hideSoftInput(); } } });
ed_search_input.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEARCH) { queryMark(ed_search_input.getText().toString().trim()); return true; } return false; } });
private void hideSoftInput() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) imm.hideSoftInputFromInputMethod(ed_search_input.getWindowToken(), 0); }