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

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

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

SearchView.setSearchableInfo介绍

暂无

代码示例

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

import android.support.v7.widget.SearchView;

...

public class YourActivity extends AppCompatActivity {

  ...

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);
    // Retrieve the SearchView and plug it into SearchManager
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return true;
  }

  ... 

}

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

this.getSupportMenuInflater().inflate(R.menu.menu, menu);
final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
final MenuItem searchItem = menu.findItem(R.id.menu_search);
final SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo(info);

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

public class Activity extends android.app.Activity
{
  @Override
  public boolean onCreateOptionsMenu( Menu menu )
  {
    getMenuInflater().inflate( R.menu.main, menu );

    // Add SearchWidget.
    SearchManager searchManager = (SearchManager) getSystemService( Context.SEARCH_SERVICE );
    SearchView searchView = (SearchView) menu.findItem( R.id.options_menu_main_search ).getActionView();

    searchView.setSearchableInfo( searchManager.getSearchableInfo( getComponentName() ) );

    return super.onCreateOptionsMenu( menu );
  }
}

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

SearchManager searchManager =
    (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
SupportMenuItem searchMenuItem = ((SupportMenuItem) menu.findItem(R.id.menu_search));
SearchView searchView = (SearchView) searchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));

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

public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater menuInflater = getMenuInflater();
  menuInflater.inflate(R.menu.dashboard, menu);

   MenuItem searchItem = menu.findItem(R.id.action_search);

  SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE);

  SearchView searchView = null;
  if (searchItem != null) {
    searchView = (SearchView) searchItem.getActionView();
  }
  if (searchView != null) {
    searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName()));
  }
    return super.onCreateOptionsMenu(menu);
}

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

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
   SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
   searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
   int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
   searchView.findViewById(searchPlateId).setBackgroundResource(R.drawable.textfield_search_selected);
   int voiceSearchPlateId = searchView.getContext().getResources().getIdentifier("android:id/submit_area", null, null);
   searchView.findViewById(voiceSearchPlateId).setBackgroundResource(R.drawable.textfield_search_right_selected);
   // change hint color
   int searchTextViewId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
   TextView searchTextView = (TextView) searchView.findViewById(searchTextViewId);
   searchTextView.setHintTextColor(getResources().getColor(R.color.light_grey));

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

// Associate searchable configuration with the SearchView
SearchManager searchManager =
   (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
   (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
  searchManager.getSearchableInfo(MainActivity.this.getComponentName()));

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

public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.menu_contacts, menu);

  SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  SearchView search = (SearchView) menu.findItem(R.id.action_search).getActionView();
  search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));

  AutoCompleteTextView searchTextView = (AutoCompleteTextView) search.findViewById(android.support.v7.appcompat.R.id.search_src_text);
  try {
    Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
    mCursorDrawableRes.setAccessible(true);
    mCursorDrawableRes.set(searchTextView, R.drawable.cursor); //This sets the cursor resource ID to 0 or @null which will make it visible on white background
  } catch (Exception e) {
  }
  return super.onCreateOptionsMenu(menu);
}

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

//associating the searchable configuration with the search service...
 SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
 SearchView searchView = (SearchView)menu.findItem(R.id.search).getActionView();
 searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

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

public boolean onCreateOptionsMenu(Menu menu) {
   super.onCreateOptionsMenu(menu);
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.action_bar, menu);
   MenuItem searchItem = menu.findItem(R.id.menu_item_search);
   SearchView searchView = (SearchView) searchItem.getActionView();
   SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
   if(null!=searchManager ) {   
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
   }
   searchView.setIconifiedByDefault(false);
   return true;
 }

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

getMenuInflater().inflate(R.menu.main, menu);
 MenuItem searchItem = menu.findItem(R.id.search);
 SearchManager searchManager =(SearchManager)getSystemService(Context.SEARCH_SERVICE);
 SearchView searchView = (SearchView)MenuItemCompat.getActionView(searchItem);
 SearchableInfo info =  searchManager.getSearchableInfo(getComponentName());
 searchView.setSearchableInfo(info);

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

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

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  SearchView searchView = (SearchView) findViewById(R.id.searchActivity_searchView);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}

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

MenuItem searchMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

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

SearchView searchView = (SearchView) findViewById(R.id.search);  
// Sets searchable configuration defined in searchable.xml for this SearchView
SearchManager searchManager =  
  (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

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

SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
if (null != searchView )
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  searchView.setIconifiedByDefault(false);

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

SearchManager searchManager =
    (SearchManager)getActivity().getSystemService(Context.SEARCH_SERVICE);
SearchableInfo searchableInfo =
    searchManager.getSearchableInfo(getActivity().getComponentName());
searchItem = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo( searchableInfo);

代码示例来源: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.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

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

SearchView searchView = (SearchView) findViewById(R.id.search);  
// Sets searchable configuration defined in searchable.xml for this SearchView
SearchManager searchManager =  
  (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

相关文章