android.support.v7.widget.SearchView.setSearchableInfo()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中android.support.v7.widget.SearchView.setSearchableInfo()方法的一些代码示例,展示了SearchView.setSearchableInfo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SearchView.setSearchableInfo()方法的具体详情如下:
包路径:android.support.v7.widget.SearchView
类名称:SearchView
方法名:setSearchableInfo

SearchView.setSearchableInfo介绍

暂无

代码示例

代码示例来源:origin: pockethub/PocketHub

@Override
public boolean onCreateOptionsMenu(Menu options) {
  getMenuInflater().inflate(R.menu.activity_search, options);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  MenuItem searchItem = options.findItem(R.id.m_search);
  searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  Bundle args = new Bundle();
  args.putParcelable(EXTRA_REPOSITORY, repository);
  searchView.setAppSearchData(args);
  return true;
}

代码示例来源:origin: pockethub/PocketHub

@Override
public boolean onCreateOptionsMenu(Menu options) {
  getMenuInflater().inflate(R.menu.activity_search, options);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  MenuItem searchItem = options.findItem(R.id.m_search);
  searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  return true;
}

代码示例来源:origin: pockethub/PocketHub

@Override
public boolean onCreateOptionsMenu(Menu optionMenu) {
  getMenuInflater().inflate(R.menu.activity_main, optionMenu);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  MenuItem searchItem = optionMenu.findItem(R.id.m_search);
  SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  return super.onCreateOptionsMenu(optionMenu);
}

代码示例来源:origin: hidroh/materialistic

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  if (mIsMultiPane) {
    getMenuInflater().inflate(R.menu.menu_item_compact, menu);
  }
  if (isSearchable()) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    MenuItem menuSearch = menu.findItem(R.id.menu_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(
        new ComponentName(this, SearchActivity.class)));
    searchView.setIconified(true);
    searchView.setQuery("", false);
  }
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: iMeiji/Toutiao

@Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    MenuItem item = menu.findItem(R.id.action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(item);
    // 关联检索配置与 SearchActivity
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchableInfo searchableInfo = searchManager.getSearchableInfo(
        new ComponentName(getApplicationContext(), SearchActivity.class));
    searchView.setSearchableInfo(searchableInfo);
    searchView.onActionViewExpanded();
//        // 设置搜索文字样式
//        EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
//        searchEditText.setTextColor(getResources().getColor(R.color.textColorPrimary));
//        searchEditText.setHintTextColor(getResources().getColor(R.color.textColorPrimary));
//        searchEditText.setBackgroundColor(Color.WHITE);
    setOnQuenyTextChangeListener();

    return super.onCreateOptionsMenu(menu);
  }

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setFocusable(false);
searchView.setIconifiedByDefault(true);

代码示例来源:origin: hidroh/materialistic

private void createSearchView(MenuItem menuSearch) {
  final SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
  searchView.setQueryHint(getString(R.string.hint_search_saved_stories));
  searchView.setSearchableInfo(((SearchManager) getActivity()
      .getSystemService(Context.SEARCH_SERVICE))
      .getSearchableInfo(getActivity().getComponentName()));
  searchView.setIconified(!mSearchViewExpanded);
  searchView.setQuery(mFilter, false);
  searchView.setOnSearchClickListener(v -> {
    mSearchViewExpanded = true;
    v.requestFocus();
  });
  searchView.setOnCloseListener(() -> {
    // trigger a dummy empty search intent, as empty query does not get submitted
    searchView.setQuery(FavoriteActivity.EMPTY_QUERY, true);
    return false;
  });
}

代码示例来源:origin: algolia/instantsearch-android

/**
 * 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 searchableInfo a SearchableInfo can be retrieved from the SearchManager, for a specific
 *                       activity or a global search provider.
 */
public void setSearchableInfo(SearchableInfo searchableInfo) {
  if (searchView != null) {
    searchView.setSearchableInfo(searchableInfo);
  } else if (supportView != null) {
    supportView.setSearchableInfo(searchableInfo);
  } else {
    throw new IllegalStateException(ERROR_NO_SEARCHVIEW);
  }
}

代码示例来源:origin: matburt/mobileorg-android

@Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.outline_menu, menu);
    synchronizerMenuItem = menu.findItem(R.id.menu_sync);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    ComponentName cn = new ComponentName(this, SearchActivity.class);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(cn));
//        searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

    return true;
  }

代码示例来源:origin: Mike-bel/MDStudySamples

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.menu_search, menu);
  SearchManager searchManager = (SearchManager) getSystemService(Service.SEARCH_SERVICE);
  SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchResultActivity.class)));
  return true;
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

@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;
}

代码示例来源:origin: sismics/reader

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.main, menu);
  // Get the SearchView and set the searchable configuration
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  searchItem = menu.findItem(R.id.action_search);
  SearchView searchView = (SearchView) searchItem.getActionView();
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: a-voyager/WeekToDo

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.menu_main, menu);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  searchView.setIconifiedByDefault(true);
  return true;
}

代码示例来源:origin: adityak368/Android-FileBrowser-FilePicker

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.toolbar_default_menu, menu);
  // Get the SearchView and set the searchable configuration
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  mSearchMenuItem = menu.findItem(R.id.action_search);
  mSearchView = (SearchView)mSearchMenuItem.getActionView();
  // Assumes current activity is the searchable activity
  mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  //searchView.setSubmitButtonEnabled(true);
  mSearchView.setOnQueryTextListener(this);
  return true;
}

代码示例来源:origin: adityak368/Android-FileBrowser-FilePicker

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.toolbar_default_menu, menu);
  // Get the SearchView and set the searchable configuration
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  mSearchMenuItem = menu.findItem(R.id.action_search);
  mSearchView = (SearchView)mSearchMenuItem.getActionView();
  // Assumes current activity is the searchable activity
  mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  //searchView.setSubmitButtonEnabled(true);
  mSearchView.setOnQueryTextListener(mSearchViewListener);
  return true;
}

代码示例来源:origin: adityak368/Android-FileBrowser-FilePicker

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.toolbar_default_menu_filechooser, menu);
  // Get the SearchView and set the searchable configuration
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  mSearchMenuItem = menu.findItem(R.id.action_search);
  mSearchView = (SearchView)mSearchMenuItem.getActionView();
  // Assumes current activity is the searchable activity
  mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  //searchView.setSubmitButtonEnabled(true);
  mSearchView.setOnQueryTextListener(this);
  return true;
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu_main, menu);

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

  SearchView searchView =
   (SearchView) menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
 }
}

代码示例来源:origin: 10clouds/InifiniteRecyclerView

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);
  SearchManager searchManager = (SearchManager)
      getSystemService(Context.SEARCH_SERVICE);
  MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
  SearchView searchView = (SearchView) searchMenuItem.getActionView();
  searchView.setSearchableInfo(searchManager.
      getSearchableInfo(getComponentName()));
  searchView.setOnQueryTextListener(this);
  MenuItemCompat.setOnActionExpandListener(searchMenuItem, this);
  return true;
}

代码示例来源:origin: amahi/android

private void setUpSearchView() {
  SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
  searchView.setSubmitButtonEnabled(false);
  searchView.setOnQueryTextListener(this);
}

代码示例来源:origin: erikcaffrey/Android-Spotify-MVP

private void setupSearchView(Menu menu) {
 SearchManager searchManager =
   (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
 SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
 searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
 searchView.setQueryHint(getString(R.string.search_hint));
 searchView.setMaxWidth(toolbar.getWidth());
 searchView.setOnQueryTextListener(this);
}

相关文章