/** * Enables showing a submit button when the query is non-empty. In cases where the SearchView * is being used to filter the contents of the current activity and doesn't launch a separate * results activity, then the submit button should be disabled. * * @param enabled true to show a submit button for submitting queries, false if a submit * button is not required. */ public void setSubmitButtonEnabled(boolean enabled) { mSubmitButtonEnabled = enabled; updateViewsVisibility(isIconified()); }
/** * Sets the default or resting state of the search field. If true, a single search icon is * shown by default and expands to show the text field and other buttons when pressed. Also, * if the default state is iconified, then it collapses to that state when the close button * is pressed. Changes to this property will take effect immediately. * * <p>The default value is true.</p> * * @param iconified whether the search field should be iconified by default * * @attr ref android.R.styleable#SearchView_iconifiedByDefault */ public void setIconifiedByDefault(boolean iconified) { if (mIconifiedByDefault == iconified) return; mIconifiedByDefault = iconified; updateViewsVisibility(iconified); updateQueryHint(); }
private void onSearchClicked() { updateViewsVisibility(false); mQueryTextView.requestFocus(); setImeVisibility(true); if (mOnSearchClickListener != null) { mOnSearchClickListener.onClick(this); } }
/** * {@inheritDoc} */ @Override public void onActionViewCollapsed() { clearFocus(); updateViewsVisibility(true); mQueryTextView.setImeOptions(mCollapsedImeOptions); mExpandedInActionView = false; }
void onTextFocusChanged() { updateViewsVisibility(isIconified()); // Delayed update to make sure that the focus has settled down and window focus changes // don't affect it. A synchronous update was not working. postUpdateFocusedState(); if (mQueryTextView.hasFocus()) { forceSuggestionQuery(); } }
/** @hide */ @Override public boolean requestFocus(int direction, Rect previouslyFocusedRect) { // Don't accept focus if in the middle of clearing focus if (mClearingFocus) return false; // Check if SearchView is focusable. if (!isFocusable()) return false; // If it is not iconified, then give the focus to the text field if (!isIconified()) { boolean result = mQueryTextView.requestFocus(direction, previouslyFocusedRect); if (result) { updateViewsVisibility(false); } return result; } else { return super.requestFocus(direction, previouslyFocusedRect); } }
private void onCloseClicked() { CharSequence text = mQueryTextView.getText(); if (TextUtils.isEmpty(text)) { if (mIconifiedByDefault) { // If the app doesn't override the close behavior if (mOnCloseListener == null || !mOnCloseListener.onClose()) { // hide the keyboard and remove focus clearFocus(); // collapse the search field updateViewsVisibility(true); } } } else { mQueryTextView.setText(""); mQueryTextView.requestFocus(); setImeVisibility(true); } }
updateViewsVisibility(mIconifiedByDefault); updateQueryHint();
/** * Sets the SearchableInfo for this SearchView. Properties in the SearchableInfo are used * to display labels, hints, suggestions, create intents for launching search results screens * and controlling other affordances such as a voice button. * * @param searchable a SearchableInfo can be retrieved from the SearchManager, for a specific * activity or a global search provider. */ public void setSearchableInfo(SearchableInfo searchable) { mSearchable = searchable; if (mSearchable != null) { updateSearchAutoComplete(); updateQueryHint(); } // Cache the voice search capability mVoiceButtonEnabled = hasVoiceSearch(); if (mVoiceButtonEnabled) { // Disable the microphone on the keyboard, as a mic is displayed near the text box // TODO: use imeOptions to disable voice input when the new API will be available mQueryTextView.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE); } updateViewsVisibility(isIconified()); }