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

x33g5p2x  于2022-01-30 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(135)

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

SearchView介绍

暂无

代码示例

代码示例来源:origin: bumptech/glide

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 MenuInflater menuInflater = getMenuInflater();
 menuInflater.inflate(R.menu.search_activity, menu);
 searchView = (SearchView) menu.findItem(R.id.search).getActionView();
 searchView.setSubmitButtonEnabled(true);
 searchView.setIconified(false);
 searchView.setOnQueryTextListener(this);
 return true;
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onSaveInstanceState(Bundle state) {
 super.onSaveInstanceState(state);
 if (!sv.isIconified()) {
  state.putString(STATE_QUERY, sv.getQuery().toString());
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

private void configureSearchView(Menu menu) {
 MenuItem search=menu.findItem(R.id.search);
 sv=(SearchView)search.getActionView();
 sv.setOnQueryTextListener(this);
 sv.setOnCloseListener(this);
 sv.setSubmitButtonEnabled(false);
 sv.setIconifiedByDefault(true);
 if (initialQuery != null) {
  sv.setIconified(false);
  search.expandActionView();
  sv.setQuery(initialQuery, true);
 }
}

代码示例来源:origin: stackoverflow.com

SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
 searchView.setIconifiedByDefault(true);
 searchView.setFocusable(true);
 searchView.setIconified(false);
 searchView.requestFocusFromTouch();

代码示例来源:origin: stackoverflow.com

@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);
  SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
  // Tells your app's SearchView to use this activity's searchable configuration
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

  return true;
}

代码示例来源:origin: stackoverflow.com

MenuItem searchMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchAutoComplete.setHintTextColor(Color.WHITE);
searchAutoComplete.setTextColor(Color.WHITE);
View searchplate = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
searchplate.setBackgroundResource(R.drawable.texfield_searchview_holo_light);
ImageView searchCloseIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
searchCloseIcon.setImageResource(R.drawable.abc_ic_clear_normal);
ImageView voiceIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_voice_btn);
voiceIcon.setImageResource(R.drawable.abc_ic_voice_search);
ImageView searchIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
searchIcon.setImageResource(R.drawable.abc_ic_search);

代码示例来源:origin: stackoverflow.com

public class MainActivity extends FragmentActivity{
  static SearchView searchView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    searchView = (SearchView)findViewById(R.id.searchView1);
    searchView.setQueryHint("Type Word...");
    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
    View searchPlate = searchView.findViewById(searchPlateId);
    if (searchPlate!=null) {
      searchPlate.setBackgroundColor(Color.WHITE);
      int searchTextId = searchPlate.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
      TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
      if (searchText!=null) {
        searchText.setTextColor(Color.DKGRAY);
        searchText.setHintTextColor(Color.LTGRAY);

        //This is what you want?
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchView.getRootView();//Notice that i change this
        searchView.setSearchableInfo(
        searchManager.getSearchableInfo(getComponentName()));
      }
    }       
}

代码示例来源:origin: SunAlwaysOnline/Sukeda

private void initSearchView(View v) {
  searchView = (SearchView) v.findViewById(R.id.sv_entry_category);
  searchView.setSubmitButtonEnabled(true);
  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String s) {
      EntryCategoryUtil.get_entry_category_mohu(s, new EntryCategoryUtil.mohu_categoryCall() {
        @Override
        public void success(final List<EntryCategory> list) {
          initSearchViewData(list);
        }
      });
      return false;
    }
    @Override
    public boolean onQueryTextChange(String s) {
      return false;
    }
  });
}

代码示例来源:origin: stackoverflow.com

searchAdapter = new SearchDialogAdapater
  (orderedBeaches, orderedBeachesIds, context, isFromZonas);

builder.setSingleChoiceItems(searchAdapter, -1, null);
builder.setPositiveButton(R.string.searchOK, searchAdapter);
builder.setNegativeButton(R.string.cancelar, null);
builder.setIcon(context.getResources().getDrawable(R.drawable.icon_beach));
builder.setTitle(StaticUtils.DIALOG_TITLE);

View dialogView = context.getLayoutInflater().inflate
  (R.layout.dialog_beaches, null);

SearchView searchView = SearchView)dialogView.findViewById
(R.id.search_beach);

searchView.setOnQueryTextListener(searchAdapter);

builder.setView(dialogView);

AlertDialog dialog = builder.create();
dialog.show();

dialog.getListView().setOnItemClickListener(searchAdapter);
searchAdapter.setDialog(dialog);
dialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);

代码示例来源:origin: stackoverflow.com

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 MenuInflater inflater = getMenuInflater();
 inflater.inflate(R.menu.menu, menu);

 MenuItem searchItem = menu.findItem(R.id.action_search);
 SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
 if (searchView != null) {
   searchView.setOnQueryTextListener(this);
 }

 return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: IHTSDO/SNOMED-in-5-minutes

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
  // Inflate the layout for this fragment
  View view = inflater.inflate(R.layout.fragment_snomed, container, false);
  unbinder = ButterKnife.bind(this, view);
  adapter = new SnomedAdapter(getContext(), getActivity());
  rvJsonResponse.setEmptyView(view.findViewById(R.id.empty_rv_view));
  tvSearchBar.setQueryHint("Type at least 3 characters  Example: shou fra");
  tvSearchBar.setOnClickListener(v -> {
    tvSearchBar.setFocusable(true);
    tvSearchBar.setIconified(false);
    tvSearchBar.requestFocusFromTouch();
  });
  tvSearchBar.setOnQueryTextListener(this);
  rvJsonResponse.setLayoutManager(new LinearLayoutManager(getContext()));
  rvJsonResponse.setAdapter(adapter);
  rvJsonResponse.setNestedScrollingEnabled(false);
  return view;
}

代码示例来源:origin: stackoverflow.com

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.menu, menu);
  MenuItem searchItem = menu.findItem(R.id.action_search);
  SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) searchItem.getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setOnQueryTextListener(queryTextListener);
  switch (item.getItemId()) {
    case R.id.action_search:
      break;
  searchView.setOnQueryTextListener(queryTextListener);
  return super.onOptionsItemSelected(item);

代码示例来源:origin: sheimi/SGit

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.repo_detail, menu);
  mSearchItem = menu.findItem(R.id.action_search);
  mSearchItem.setOnActionExpandListener(mTabItemPagerAdapter);
  mSearchItem.setVisible(mSelectedTab == COMMITS_FRAGMENT_INDEX);
  SearchView searchView = (SearchView) mSearchItem.getActionView();
  if (searchView != null) {
    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(mTabItemPagerAdapter);
  }
  return true;
}

代码示例来源:origin: stackoverflow.com

inflater.inflate(R.menu.conversation_index_activity_menu, menu);
mSearchView = (SearchView) menu.findItem(R.id.itemSearch).getActionView();
MenuItem menuItem = menu.findItem(R.id.itemSearch);
  menuItem.setOnActionExpandListener(new OnActionExpandListener()
  mSearchView.setOnCloseListener(new OnCloseListener()

代码示例来源:origin: stackoverflow.com

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  super.onCreateOptionsMenu(menu, inflater);
  menu.clear();
  inflater.inflate(R.menu.search, menu);
  SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

  searchView.setOnQueryTextListener(new SearchTextListener());
  changeSearchViewTextColor(searchView);
}

private void changeSearchViewTextColor(View view) {
  if (view != null) {
    if (view instanceof TextView) {
      ((TextView) view).setTextColor(Color.BLACK);
      return;
    } else if (view instanceof ViewGroup) {
      ViewGroup viewGroup = (ViewGroup) view;
      for (int i = 0; i < viewGroup.getChildCount(); i++) {
        changeSearchViewTextColor(viewGroup.getChildAt(i));
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

@Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   inflater.inflate(R.menu.main, menu); // removed to not double the menu items
   MenuItem item = menu.findItem(R.id.action_search);
   SearchView sv = new SearchView(((MainActivity) getActivity()).getSupportActionBar().getThemedContext());
   changeSearchViewTextColor(sv);
   MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
   MenuItemCompat.setActionView(item, sv);
   sv.setOnQueryTextListener(this);
   sv.setIconifiedByDefault(false);
   sv.setQuery(((MainActivity)getActivity()).searchView.getQuery()); // set the main activity's search view query in the fragment's search view
   super.onCreateOptionsMenu(menu, inflater);
 }

代码示例来源:origin: stackoverflow.com

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.bookings_list_menu, menu);
  SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();

  searchView.setOnSearchClickListener(...);
  searchView.setOnCloseListener(...);
  searchView.setOnQueryTextListener(...);

  super.onCreateOptionsMenu(menu, inflater);
}

代码示例来源:origin: stackoverflow.com

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_search, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(getApplicationContext(), SearchActivity.class)));
searchView.setMaxWidth(Integer.MAX_VALUE);
MenuItemCompat.expandActionView(menu.findItem(R.id.search));
searchView.setIconifiedByDefault(true);
searchView.setIconified(false);

代码示例来源:origin: stackoverflow.com

public class TestActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.test);

  final View btnClear = findViewById(R.id.btnSentSearchClear);
  SearchView sv = (SearchView) findViewById(R.id.svMailSent);
  sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
      return false;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
      btnClear.setVisibility(newText!=null 
        && !newText.isEmpty() ? View.VISIBLE : View.GONE);
      return false;
    }
  });
}

代码示例来源:origin: stackoverflow.com

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getSupportMenuInflater().inflate(R.menu.main, menu);

  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  SearchView searchView = (SearchView) menu.findItem(R.id.menu_search)
      .getActionView();
  if (null != searchView) {
    searchView.setSearchableInfo(searchManager
        .getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
  }

  SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
    public boolean onQueryTextChange(String newText) {
      // this is your adapter that will be filtered
      return true;
    }

    public boolean onQueryTextSubmit(String query) {
      //Here u can get the value "query" which is entered in the search box.

    }
  };
  searchView.setOnQueryTextListener(queryTextListener);

  return super.onCreateOptionsMenu(menu);
}

相关文章