SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); searchView.setIconified(false); searchView.clearFocus();
private SearchView searchView; @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.search_menu, menu); searchView = (SearchView) menu.findItem(R.id.menu_search) .getActionView(); // set the reference to the searchView searchView.setOnQueryTextListener(this); searchMenuItem = (MenuItem) menu.findItem(R.id.menu_search); searchMenuItem.expandActionView(); // expand the search action item automatically searchView.setQuery("<put your search term here>", false); // fill in the search term by default searchView.clearFocus(); // close the keyboard on load return true; } @Override public boolean onQueryTextSubmit(String query) { performNewSearch(query); searchView.clearFocus(); return true; }
@Override public boolean onQueryTextSubmit(String query) { mSearchExpanded = true; mState.currentSearch = query; mSearchView.clearFocus(); onCurrentDirectoryChanged(ANIM_NONE); return true; } @Override
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); //Define your Searchview SearchView searchView = (SearchView) findViewById(R.id.search_bar); //Turn iconified to false: searchView.setIconified(false); //The above line will expand it to fit the area as well as throw up the keyboard //To remove the keyboard, but make sure you keep the expanded version: searchView.clearFocus(); }
@Override public boolean onQueryTextSubmit(String s) { //book_list=null; BookUtil.page = 1; BookUtil.all_books = 0; initData(s); setAblExpanded(false); //搜索后失去焦点 searchView.clearFocus(); return false; }
MenuItem searchItem = menu.findItem(R.id.menu_item_search); SearchView mSearchView = (SearchView) menu.findItem(R.id.menu_item_search).getActionView(); if (mSearchView!=null && searchItem!=null) { mSearchView.clearFocus(); searchItem.collapseActionView(); }
/** * Called when this view wants to give up focus. If focus is cleared * {@link View#onFocusChanged(boolean, int, android.graphics.Rect)} is called. * <p> * <strong>Note:</strong> When a View clears focus the framework is trying * to give focus to the first focusable View from the top. Hence, if this * View is the first from the top that can take focus, then all callbacks * related to clearing focus will be invoked after which the framework will * give focus to this view. * </p> */ public void clearFocus() { if (searchView != null) { searchView.clearFocus(); } else if (supportView != null) { supportView.clearFocus(); } else { throw new IllegalStateException(ERROR_NO_SEARCHVIEW); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); searchView.setIconified(false); searchView.setIconifiedByDefault(false); searchView.clearFocus(); } }
@Override public void onPrepareOptionsMenu(Menu menu) { final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search)); if(!TextUtils.isEmpty(mSearch)){ searchView.setQuery(mSearch, false); searchView.setIconified(false); searchView.clearFocus(); } }
SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.clearFocus(); View focused = searchView.getFocusedChild(); if (focused != null) { focused.clearFocus(); }
protected void hideKeyboard() { InputMethodManager imm = (InputMethodManager) mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getApplicationWindowToken(), 0); mIsKeyboardShowing = false; mSearchView.clearFocus(); mDrawerView.findViewById(R.id.agingDrawerScroll).requestFocusFromTouch(); }
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); // Saving the query during of on handle intent SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionsProvider.AUTHORITY, SearchSuggestionsProvider.MODE); suggestions.saveRecentQuery(query, null); try { query = URLEncoder.encode(query, "utf-8"); } catch (UnsupportedEncodingException e) { Log.w(TAG, "Can't encode search query", e); } initSearchEndpointAndUrlParams(query); mDialog.setMessage(getString(R.string.loading_more_data)); mDialog.getWindow().setGravity(Gravity.CENTER); mDialog.show(); loadSearchResults(); mSearchView.clearFocus(); } }
public boolean onQueryTextSubmit(String s) { Log.i(TAG,"onQueryTextSubmit: " + s); searchView.clearFocus(); return true;
final SearchView sv = new SearchView(((MainActivity) getActivity()).getSupportActionBar().getThemedContext()); sv.setIconifiedByDefault(true); sv.setFocusable(true); sv.setIconified(false); sv.clearFocus(); sv.requestFocusFromTouch();
search.expandActionView(); mSearchView.setIconified(false); mSearchView.clearFocus(); mSearchView.setQuery(mState.currentSearch, false); } else { mIgnoreNextClose = true; mSearchView.setIconified(true); mSearchView.clearFocus(); mIgnoreNextCollapse = true; search.collapseActionView();
@Override public boolean onQueryTextSubmit(String query) { sv_phone.clearFocus(); ShowDialogUtil.showProgressDialog(getActivity(), "正在查询..."); PhoneUtil.get_phone(query, new PhoneUtil.getPhone_mohuCall() { @Override public void success(final List<DepartmentPhone> list) { ShowDialogUtil.closeProgressDialog(); new MaterialDialog.Builder(getActivity()) .title("点击即可跳转到拨号界面") .negativeText("取消") .items(list) .itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) { Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + list.get(position).getPhone())); getActivity().startActivity(i); } }) .show(); } @Override public void fail() { } }); return false; }
searchView.clearFocus();
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.my_list, menu); final MenuItem searchItem = menu.findItem(R.id.action_search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { //Fetch the data remotely FetchData(query); //Reset the SearchView searchView.clearFocus(); searchView.setQuery("", false); searchView.setIconified(true); searchItem.collapseActionView(); //Set Activity title to search query MainActivity.this.setTitle(query); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); return true; }
public void onBackPressed() { int count = getSupportFragmentManager().getBackStackEntryCount(); if (count == 1) { String tag = getSupportFragmentManager().getBackStackEntryAt(0).getName(); super.onBackPressed(); searchView.setVisibility(View.VISIBLE); searchView.clearFocus(); recyclerView.setVisibility(View.VISIBLE); if (tag != null && tag.equals("detail")) { return; } if (abl_library != null) { setAblExpanded(true); } return; } if (count == 0) { if (abl_state != STATE.EXPANDED) { setAblExpanded(true); } else { startActivity(new Intent(LibraryActivity.this, HomeActivity.class)); overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right); super.onBackPressed(); } } }
private void initComponents() { application = (MusicApplication) getApplication(); /*搜索结果为空时,显示的提示信息*/ textTips = (TextView) findViewById(R.id.text_tips); /*按钮类组件初始化*/ searchBack = (ImageButton) findViewById(R.id.image_search_back); searchOption = (ImageButton) findViewById(R.id.image_search_option); searchBack.setOnClickListener(this); searchOption.setOnClickListener(this); /*列表组件初始化*/ listView = (ListView) findViewById(R.id.list_search_result); listView.setOnItemClickListener(this); listView.setVisibility(View.INVISIBLE); loadData(); /*搜索组件初始化*/ searchView = (SearchView) findViewById(R.id.view_search); searchView.setOnQueryTextListener(this); searchView.onActionViewExpanded(); // 默认出现点击输入状态 searchView.setFocusable(false); searchView.clearFocus(); // searchView.setSubmitButtonEnabled(true); }