android.support.v7.widget.SearchView Java Examples

The following examples show how to use android.support.v7.widget.SearchView. 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: MainActivity.java    From recycler-view-search with MIT License 6 votes vote down vote up
private void search(SearchView searchView) {

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {

                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {

                if (mAdapter != null) mAdapter.getFilter().filter(newText);
                return true;
            }
        });
    }
 
Example #2
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example #3
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example #4
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example #5
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example #6
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example #7
Source File: ZhuanTiActivity.java    From MaterialWpp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem menuItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (null != manager) {
                manager.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
            }
            Intent intent = new Intent(ZhuanTiActivity.this, SearchActivity.class);
            intent.putExtra("keyword",query);
            startActivity(intent);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    return true;
}
 
Example #8
Source File: BaseContactFragment.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    if (userSearch) {
        inflater.inflate(R.menu.compose, menu);

        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                filter(newText);
                return true;
            }
        });
    }
}
 
Example #9
Source File: EarthquakeMainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
Example #10
Source File: RecentActivity.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.recentmenu, menu);

    MenuItem searchItem = menu.findItem(R.id.recentmenu_searchBook);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            ActionEx a = getController().getOrCreateAction(R.id.actions_searchBook);
            a.addParameter(new Constant("input", new SpannableStringBuilder(query)));
            a.run();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    return true;
}
 
Example #11
Source File: PhotosListActivity.java    From photoviewer with Apache License 2.0 6 votes vote down vote up
private void setUpSearchMenu(Menu menu) {
    // Associate searchable configuration with the SearchView
    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =
            (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(getComponentName()));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mPhotoListPresenter.searchByTitle(newText);
            return true;
        }
    });
    searchView.setOnCloseListener(() -> {
        mPhotoListPresenter.searchByTitle(null);
        return false;
    });
}
 
Example #12
Source File: QuestionsActivity.java    From mvp-android-arch-component with MIT License 6 votes vote down vote up
@Override public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.questions, menu);

  // Setup search widget in action bar
  SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  searchView.setQueryHint(getString(R.string.search_hint));
  searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);

  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override public boolean onQueryTextSubmit(String query) {
      return false;
    }

    @Override public boolean onQueryTextChange(String newText) {
      presenter.search(newText);
      return true;
    }
  });

  return true;
}
 
Example #13
Source File: MainActivity.java    From fuckView with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    final MenuItem item = menu.findItem(R.id.action_search);
    SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(item);
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (shouldShowFAQ) {
                ((Searchable) currentFragment).setSearchText(newText);
            }
            return true;
        }
    });
    return super.onCreateOptionsMenu(menu);
}
 
Example #14
Source File: SubsonicFragment.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
protected void onFinishSetupOptionsMenu(final Menu menu) {
	searchItem = menu.findItem(R.id.menu_global_search);
	if(searchItem != null) {
		searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
		SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
		SearchableInfo searchableInfo = searchManager.getSearchableInfo(context.getComponentName());
		if(searchableInfo == null) {
			Log.w(TAG, "Failed to get SearchableInfo");
		} else {
			searchView.setSearchableInfo(searchableInfo);
		}

		String currentQuery = getCurrentQuery();
		if(currentQuery != null) {
			searchView.setOnSearchClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					searchView.setQuery(getCurrentQuery(), false);
				}
			});
		}
	}
}
 
Example #15
Source File: ActivityMain.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
private void init() {
    UpodsApplication.initAllResources();
    vOverlay = findViewById(R.id.vOverlay);

    //Toolbar
    toolbar.inflateMenu(R.menu.menu_activity_main);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setTitleTextColor(getResources().getColor(R.color.white));

    //Social
    callbackManager = CallbackManager.Factory.create();

    MenuItem searchMenuItem = toolbar.getMenu().findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    UIHelper.setSearchViewStyle(searchView);
    UIHelper.changeSearchViewTextColor(searchView, Color.WHITE);

    slidingMenu = new SlidingMenu(this, toolbar);
}
 
Example #16
Source File: MainActivity.java    From ListViewVariants with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menuItem_search));
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(final String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(final String newText) {
            performSearch(newText);
            return true;
        }
    });

    return super.onCreateOptionsMenu(menu);
}
 
Example #17
Source File: MainActivity.java    From vk_music_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main_toolbar, menu);
    this.optionsMenu = menu;

    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchFragment.search(query);
            showSearchFragment();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}
 
Example #18
Source File: MainActivity.java    From Moticons with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);

    searchItem = menu.findItem(R.id.action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    moticoinsItem = menu.findItem(R.id.action_moticoins);
    moticoinsItem.setTitle(String.format(getResources().getString(R.string.moticoins_value), appPreferences.getMoticoins()));

    return true;
}
 
Example #19
Source File: MainActivity.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
/** Create menu from XML
 */
@TargetApi(Build.VERSION_CODES.FROYO)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mMenu = menu;
    /* Note: on Android 3.0+ with an action bar this method
     * is called while the view is created. This can happen
     * any time after onCreate.
     */
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.media_library, menu);

    if (AndroidUtil.isFroyoOrLater()) {
        SearchManager searchManager =
                (SearchManager) VLCApplication.getAppContext().getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setQueryHint(getString(R.string.search_hint));
        SearchSuggestionsAdapter searchSuggestionsAdapter = new SearchSuggestionsAdapter(this, null);
        searchSuggestionsAdapter.setFilterQueryProvider(this);
        mSearchView.setSuggestionsAdapter(searchSuggestionsAdapter);
    } else
        menu.findItem(R.id.ml_menu_search).setVisible(false);
    return super.onCreateOptionsMenu(menu);
}
 
Example #20
Source File: RxSearch.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
public static Observable<String> fromSearchView(@NonNull final SearchView searchView) {
    final BehaviorSubject<String> subject = BehaviorSubject.create();

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            subject.onNext(query);
            subject.onComplete();
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            subject.onNext(newText);
            return true;
        }
    });

    return subject;
}
 
Example #21
Source File: OrdersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.order_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.order_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example #22
Source File: LibraryBrowserFragment.java    From bubble with MIT License 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    inflater.inflate(R.menu.browser, menu);

    MenuItem searchItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example #23
Source File: SearchViewUtils.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
public static void setSearchIcon(@NonNull final SearchView searchView,
        @DrawableRes final int icon) {
    View iconView = searchView
            .findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    if (iconView instanceof ImageView) {
        ((ImageView) iconView).setImageResource(icon);
    }

    iconView = searchView
            .findViewById(android.support.v7.appcompat.R.id.search_button);
    if (iconView instanceof ImageView) {
        ((ImageView) iconView).setImageResource(icon);
    }
}
 
Example #24
Source File: BuildpropFragment.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.build_prop_menu, menu);

    searchItem = menu.findItem(R.id.search);
    SearchView searchView = new SearchView(getActionBar().getThemedContext());
    searchView.setQueryHint(getString(R.string.search));

    MenuItemCompat.setActionView(searchItem, searchView);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            removeAllViews();

            Object[] keys = buildpropItem.keySet().toArray();
            Object[] values = buildpropItem.values().toArray();
            for (int i = 0; i < keys.length; i++)
                if (((String) keys[i]).contains(newText)) {
                    PopupCardView.DPopupCard mPopupCard = new PopupCardView.DPopupCard(null);
                    mPopupCard.setDescription(newText.isEmpty() ?
                            (String) keys[i] : Html.fromHtml(((String) keys[i]).replace(newText, "" +
                            "<b><font color=\"#2A7289\">" + newText + "</font></b>")));
                    mPopupCard.setItem((String) values[i]);
                    mPopupCard.setOnClickListener(BuildpropFragment.this);

                    addView(mPopupCard);
                }
            return true;
        }
    });
}
 
Example #25
Source File: SearchFragment.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void addBaseToolbarMenu(Menu menu) {
    super.addBaseToolbarMenu(menu);
    menu.add(R.string.copy_link)
            .setOnMenuItemClickListener(menuItem -> {
                Utils.copyToClipBoard(settings.toUrl());
                return false;
            });
    toolbar.inflateMenu(R.menu.qms_contacts_menu);

    settingsMenuItem = menu.add(R.string.settings)
            .setIcon(R.drawable.ic_toolbar_tune).setOnMenuItemClickListener(menuItem -> {
                hidePopupWindows();
                if (searchSettingsView != null && searchSettingsView.getParent() != null && searchSettingsView.getParent() instanceof ViewGroup) {
                    ((ViewGroup) searchSettingsView.getParent()).removeView(searchSettingsView);
                }
                if (searchSettingsView != null) {
                    dialog.setContentView(searchSettingsView);
                    dialog.show();
                }
                return false;
            });
    settingsMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);

    searchItem = menu.findItem(R.id.action_search);
    searchView = (SearchView) searchItem.getActionView();
    searchView.setIconifiedByDefault(true);
}
 
Example #26
Source File: SearchActivity.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (isInputMode) {
        menu.findItem(R.id.action_info).setVisible(false);
        menu.findItem(R.id.action_sort).setVisible(false);
        SearchView searchView = (SearchView) MenuItemCompat.
                getActionView(menu.findItem(R.id.action_search));
        searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false);
    } else {
        menu.findItem(R.id.action_info).setVisible(false);
        menu.findItem(R.id.action_sort).setVisible(pagerAdapter.getCount() != 0);
    }
    return super.onPrepareOptionsMenu(menu);
}
 
Example #27
Source File: ForumActivity.java    From uservoice-android-sdk with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.uv_forum, menu);
    MenuItem searchItem = menu.findItem(R.id.uv_menu_search);
    if (hasActionBar()) {
        MenuItemCompat.setOnActionExpandListener(searchItem, new SearchExpandListener(this));
        SearchView search = (SearchView) MenuItemCompat.getActionView(searchItem);
        search.setOnQueryTextListener(new SearchQueryListener(this));
    } else {
        searchItem.setVisible(false);
    }
    menu.findItem(R.id.uv_new_idea).setVisible(Session.getInstance().getConfig(this).shouldShowPostIdea());
    return true;
}
 
Example #28
Source File: SearchActivity.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_search, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) menu.findItem(R.id.search).getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    //展开searchview
    mSearchView.setIconified(false);
    //显示默认框内标签
    mSearchView.setIconifiedByDefault(true);

    mToolbar.setTitle("");
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
            intent.putExtra("q", query);
            UIUtils.startActivity(intent);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    return true;
}
 
Example #29
Source File: MainActivity.java    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.main_menu, menu);
    mMenuItem = menu.findItem(R.id.action_search);
    try {
        searchView = (SearchView) MenuItemCompat.getActionView(mMenuItem);
        searchView.setOnQueryTextListener(queryListener);
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }

    return super.onCreateOptionsMenu(menu);

}
 
Example #30
Source File: ListReadLaterFragment.java    From CodePolitan with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
    super.onCreateOptionsMenu(menu, inflater);
    searchView = (SearchView) menu.getItem(0).getActionView();
    searchView.setOnQueryTextListener(this);
}