List of usage examples for android.widget SearchView getWindowToken
public IBinder getWindowToken()
From source file:com.jwork.dhammapada.ChapterFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override// w w w . j a v a 2 s.c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { log.d(this, "onCreateView()"); view = inflater.inflate(R.layout.chapter_list, container, false); if (view == null) { log.w(this, "Problem inflating view, returned null"); return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final android.widget.SearchView svSearch = (android.widget.SearchView) view .findViewById(R.id.sv_search); svSearch.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(svSearch.getWindowToken(), 0); search(query); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); } else { ImageButton btnSearch = (ImageButton) view.findViewById(R.id.button_search); btnSearch.setOnClickListener(this); // txtSearch = (EditText)view.findViewById(R.id.text_search); // txtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { // @Override // public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // if (actionId == EditorInfo.IME_ACTION_SEARCH) { // search(v.getText()); // return true; // } // return false; // } // }); } return view; }
From source file:com.numenta.taurus.instance.InstanceListActivity.java
private void configureSearchView(@NonNull final SearchView searchView) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // Handle query events searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*from www. j a va 2 s. c o m*/ public boolean onQueryTextSubmit(String query) { // Hide Keyboard on submit InputMethodManager imm = (InputMethodManager) searchView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0); } return true; } @Override public boolean onQueryTextChange(String newText) { // Filter list as the user types _listFragment.applyFilter(newText); return true; } }); // FIXME: Android does not support styling the search view across all versions. // For now, "peek" into internal API to make the appropriate changes to the SearchView. // In the future we should use the official android API to customize the SearchView widget. // See android.R.layout.search_view for the layout we are "peeking". It is no guarantee it // will work on all public android versions and/or OEM customizations. // This HACK is only valid for the POC phase. We should find a better solution before releasing Resources resources = searchView.getResources(); // Style search box and text int searchPlateId = resources.getIdentifier("android:id/search_plate", null, null); View searchPlate = searchView.findViewById(searchPlateId); if (searchPlate != null) { int searchTextId = resources.getIdentifier("android:id/search_src_text", null, null); TextView searchText = (TextView) searchPlate.findViewById(searchTextId); if (searchText != null) { searchPlate.setBackgroundResource(android.R.drawable.editbox_background); searchText.setPadding(5, 0, 0, 0); searchText.setTextColor(Color.BLACK); searchText.setHintTextColor(Color.LTGRAY); } } }