android.support.v7.widget.SearchView类的使用及代码示例

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

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

SearchView介绍

暂无

代码示例

代码示例来源:origin: aa112901/remusic

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
  getMenuInflater().inflate(R.menu.menu_search, menu);
  mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
  mSearchView.setOnQueryTextListener(this);
  mSearchView.setQueryHint(getResources().getString(R.string.search_local_music));
  mSearchView.setIconifiedByDefault(false);
  mSearchView.setIconified(false);
  MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.menu_search), new MenuItemCompat.OnActionExpandListener() {
    @Override
    public boolean onMenuItemActionExpand(MenuItem item) {
      return true;
    }
    @Override
    public boolean onMenuItemActionCollapse(MenuItem item) {
      finish();
      return false;
    }
  });
  menu.findItem(R.id.menu_search).expandActionView();
  return super.onCreateOptionsMenu(menu);
}

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

searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setFocusable(false);
searchView.setIconifiedByDefault(true);
searchView.setMaxWidth(Integer.MAX_VALUE);
searchView.setQueryHint("请输入URL关键字...");
searchView.setOnSearchClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
  @Override
  public boolean onQueryTextSubmit(String query) {

代码示例来源: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: aa112901/remusic

public void hideInputManager() {
  if (mSearchView != null) {
    if (mImm != null) {
      mImm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
    }
    mSearchView.clearFocus();
    SearchHistory.getInstance(this).addSearchString(mSearchView.getQuery().toString());
  }
}

代码示例来源:origin: naman14/Timber

public void hideInputManager() {
  if (mSearchView != null) {
    if (mImm != null) {
      mImm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
    }
    mSearchView.clearFocus();
    SearchHistory.getInstance(this).addSearchString(queryString);
  }
}

代码示例来源:origin: jgilfelt/chuck

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.chuck_main, menu);
  MenuItem searchMenuItem = menu.findItem(R.id.search);
  SearchView searchView = (SearchView) searchMenuItem.getActionView();
  searchView.setOnQueryTextListener(this);
  searchView.setIconifiedByDefault(true);
  super.onCreateOptionsMenu(menu, inflater);
}

代码示例来源:origin: nglauber/dominando_android2

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.menu_hotel, menu);
  MenuItem searchItem = menu.findItem(R.id.action_search);
  SearchView searchView = (SearchView)
      MenuItemCompat.getActionView(searchItem);
  searchView.setOnQueryTextListener(this);
  searchView.setQueryHint(getString(R.string.hint_busca));
  MenuItemCompat.setOnActionExpandListener(searchItem, this);
  return true;
}

代码示例来源:origin: smuyyh/BookReader

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

代码示例来源: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: anitaa1990/TrailersApp

private void initialiseView() {
  binding = DataBindingUtil.setContentView(this, R.layout.activity_search);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  binding.search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  binding.search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
  binding.search.setIconifiedByDefault(false);
  binding.search.setOnQueryTextListener(this);
  EditText searchEditText = binding.search.findViewById(android.support.v7.appcompat.R.id.search_src_text);
  searchEditText.setTextColor(getResources().getColor(android.R.color.white));
  searchEditText.setHintTextColor(getResources().getColor(android.R.color.white));
  Typeface myCustomFont = ResourcesCompat.getFont(getApplicationContext(), R.font.gt_medium);
  searchEditText.setTypeface(myCustomFont);
  searchListAdapter = new TvSearchListAdapter(this);
  binding.includedLayout.moviesList.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false));
  binding.includedLayout.moviesList.setAdapter(searchListAdapter);
  SnapHelper startSnapHelper = new PagerSnapHelper(position -> {
    TvEntity trailer = searchListAdapter.getItem(position);
    updateBackground(trailer.getPosterPath());
  });
  startSnapHelper.attachToRecyclerView(binding.includedLayout.moviesList);
  binding.includedLayout.moviesList.addOnItemTouchListener(new RecyclerItemClickListener(getApplicationContext(), this));
}

代码示例来源:origin: szpnygo/NoWordsChat

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.search, menu);
  menu.findItem(R.id.action_search).expandActionView();
  mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  mSearchView.setQueryHint("搜索好友");
  mSearchView.setQuery(getIntent().getStringExtra("query"), true);
  mSearchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
  mSearchView.setIconifiedByDefault(true);
  mSearchView.setIconified(false);
  mSearchView.clearFocus();
  mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
      presenter.search(query);
      return false;
    }
    @Override
    public boolean onQueryTextChange(String newText) {
      return false;
    }
  });
  presenter.search(getQuery());
  return true;
}

代码示例来源:origin: AppLozic/Applozic-Android-SDK

@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  showActionBar();
  //return false;
  getMenuInflater().inflate(R.menu.mobicom_basic_menu_for_normal_message, menu);
  MenuItem searchItem = menu.findItem(R.id.menu_search);
  searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setQueryHint(getResources().getString(R.string.search_hint));
  if (Utils.hasICS()) {
    searchItem.collapseActionView();
  }
  searchView.setOnQueryTextListener(this);
  searchView.setSubmitButtonEnabled(true);
  searchView.setIconifiedByDefault(true);
  if (quickConversationFragment != null && !TextUtils.isEmpty(quickConversationFragment.getSearchString())) {
    searchView.setIconified(false);
    searchView.setQuery(quickConversationFragment.getSearchString(), false);
  }
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: materialos/android-icon-pack

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.icons, menu);
  super.onCreateOptionsMenu(menu, inflater);
  MenuItem mSearchItem = menu.findItem(R.id.search);
  SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);
  mSearchView.setQueryHint(getString(R.string.search_icons));
  mSearchView.setOnQueryTextListener(this);
  mSearchView.setOnCloseListener(this);
  mSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
  if (getActivity() != null) {
    final BaseThemedActivity act = (BaseThemedActivity) getActivity();
    TintUtils.themeSearchView(act.getToolbar(), mSearchView, DialogUtils.resolveColor(act, R.attr.tab_icon_color));
  }
}

代码示例来源: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);
}

代码示例来源:origin: AppLozic/Applozic-Android-SDK

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.menu_contact, menu);
  MenuItem searchItem = menu.findItem(R.id.menu_search);
  searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setQueryHint(getResources().getString(R.string.search_hint));
  if (Utils.hasICS()) {
    searchItem.collapseActionView();
  }
  searchView.setOnQueryTextListener(this);
  searchView.setSubmitButtonEnabled(true);
  searchView.setIconified(true);
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: 0xZhangKe/ShiZhong

private void setupSearchView(final SearchView searchView) {
  searchView.setIconified(true);
  searchView.setIconifiedByDefault(false);
  searchView.setSubmitButtonEnabled(true);
  searchView.setFocusable(true);
  searchView.requestFocusFromTouch();
  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
      return false;
    }
    @Override
    public boolean onQueryTextChange(String newText) {
      curQueryText = newText;
      search();
      return true;
    }
  });
}

代码示例来源:origin: qqq3/good-weather

private void setupSearchView() {
  SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
  SearchView searchView = (SearchView) findViewById(R.id.search_view);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  searchView.setIconified(false);
  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
      mSearchCityAdapter.getFilter().filter(query);
      return true;
    }
    @Override
    public boolean onQueryTextChange(String newText) {
      mSearchCityAdapter.getFilter().filter(newText);
      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: smuyyh/BookReader

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

代码示例来源:origin: Odoo-mobile/framework

public void setHasSearchView(IOnSearchViewChangeListener listener,
               Menu menu, int menu_id) {
  mOnSearchViewChangeListener = listener;
  mSearchView = (SearchView) MenuItemCompat.getActionView(menu
      .findItem(menu_id));
  if (mSearchView != null) {
    mSearchView.setOnCloseListener(closeListener);
    mSearchView.setOnQueryTextListener(searchViewQueryListener);
    mSearchView.setIconifiedByDefault(true);
  }
}

相关文章