Java Code Examples for android.support.v7.widget.SearchView#clearFocus()

The following examples show how to use android.support.v7.widget.SearchView#clearFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FriendSearchActivity.java    From CoolChat with Apache License 2.0 5 votes vote down vote up
private void initViews() {
    layout_points = (LinearLayout) findViewById(R.id.layout_points);
    SearchView searchView = (SearchView) findViewById(R.id.search_view);
    //设置显示提交按钮
    searchView.setSubmitButtonEnabled(true);
    //一开始就处于显示SearchView的状态
    searchView.setIconifiedByDefault(false);
    //设置一开始就显示输入框
    searchView.setIconified(true);
    searchView.clearFocus();
    SearchView.SearchAutoComplete editText = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchFriend(query.trim());
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!newText.isEmpty()) {
                searchFriend(newText);
            }
            return false;
        }
    });
}
 
Example 2
Source File: PagerResultsFragment.java    From open with GNU General Public License v3.0 5 votes vote down vote up
private Callback<Result> getSearchCallback(final SearchView view) {
    return new Callback<Result>() {
        @Override
        public void success(Result result, retrofit.client.Response response) {
            setSearchResults(result.getFeatures());
            act.hideLoadingIndicator();
            view.clearFocus();
        }

        @Override
        public void failure(RetrofitError error) {
            onServerError(error);
        }
    };
}
 
Example 3
Source File: BaseActivity.java    From open with GNU General Public License v3.0 5 votes vote down vote up
private void resetSearchView() {
    final SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setQuery("", false);
    searchView.clearFocus();
    searchView.setIconified(true);
    autoCompleteAdapter.resetCursor();
    autoCompleteAdapter.loadSavedSearches();
}
 
Example 4
Source File: SearchActivity.java    From CrimeTalk-Reader with Apache License 2.0 2 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.activity_search, menu);

    // Modify some aspects of the SearchView
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setQuery(mQuery, false);
    searchView.setIconified(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {

            return false;

        }

        @Override
        public boolean onQueryTextChange(String query) {

            SearchActivity.this.mQuery = query;

            return false;

        }

    });

    final SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete)
            searchView.findViewById(R.id.search_src_text);
    searchAutoComplete.setTextColor(getResources().getColor(R.color.white));

    // Recovering from orientation change, try not to have focus
    if (mQuery != null && !mQuery.isEmpty()) {

       searchView.clearFocus();

    }

    return true;

}