Search in sources :

Example 51 with SearchView

use of android.widget.SearchView in project OpenBikeSharing by bparmentier.

the class StationsListActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.optionsMenu = menu;
    getMenuInflater().inflate(R.menu.stations_list, menu);
    if (jsonDownloadTask != null && (jsonDownloadTask.getStatus() == AsyncTask.Status.PENDING || jsonDownloadTask.getStatus() == AsyncTask.Status.RUNNING)) {
        setRefreshActionButtonState(true);
    }
    SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            loadData(s);
            return true;
        }
    });
    return true;
}
Also used : SearchView(android.widget.SearchView) SearchManager(android.app.SearchManager)

Example 52 with SearchView

use of android.widget.SearchView in project android_packages_apps_Settings by crdroidandroid.

the class SearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.search_panel, container, false);
    mResultsRecyclerView = view.findViewById(R.id.list_results);
    mResultsRecyclerView.setAdapter(mSearchAdapter);
    mResultsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mResultsRecyclerView.addOnScrollListener(mScrollListener);
    mNoResultsView = view.findViewById(R.id.no_results_layout);
    Toolbar toolbar = view.findViewById(R.id.search_toolbar);
    getActivity().setActionBar(toolbar);
    getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
    mSearchView = toolbar.findViewById(R.id.search_view);
    mSearchView.setQuery(mQuery, false);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.requestFocus();
    // Updating internal views inside SearchView was the easiest way to get this too look right.
    // Instead of grabbing the TextView directly, we grab it as a view and do an instanceof
    // check. This ensures if we return, say, a LinearLayout in the tests, they won't fail.
    View searchText = mSearchView.findViewById(com.android.internal.R.id.search_src_text);
    if (searchText instanceof TextView) {
        TextView searchTextView = (TextView) searchText;
        searchTextView.setTextColor(getContext().getColorStateList(com.android.internal.R.color.text_color_primary));
        searchTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.search_bar_text_size));
    }
    View editFrame = mSearchView.findViewById(com.android.internal.R.id.search_edit_frame);
    if (editFrame != null) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) editFrame.getLayoutParams();
        params.setMarginStart(0);
        editFrame.setLayoutParams(params);
    }
    ActionBarShadowController.attachToRecyclerView(view.findViewById(R.id.search_bar_container), getLifecycle(), mResultsRecyclerView);
    return view;
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(android.widget.Toolbar)

Example 53 with SearchView

use of android.widget.SearchView in project android-support-v4-googlemaps by petedoyle.

the class CursorFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    SearchView sv = new SearchView(getActivity());
    sv.setOnQueryTextListener(this);
    item.setActionView(sv);
}
Also used : SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem)

Example 54 with SearchView

use of android.widget.SearchView in project weiciyuan by qii.

the class SearchMainParentFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.actionbar_menu_searchmainactivity, menu);
    final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setMaxWidth(Utility.dip2px(250));
    ThemeUtility.customActionBarSearchViewTextColor(searchView);
    searchView.requestFocus();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            search(q);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            SearchMainParentFragment.this.q = newText;
            return false;
        }
    });
    searchView.setOnSearchClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            search(q);
        }
    });
    if (!TextUtils.isEmpty(this.q)) {
        searchView.setQuery(this.q, false);
    }
}
Also used : SearchView(android.widget.SearchView) SearchManager(android.app.SearchManager) View(android.view.View) SearchView(android.widget.SearchView) TextView(android.widget.TextView)

Example 55 with SearchView

use of android.widget.SearchView in project bitcoin-wallet by bitcoin-wallet.

the class ExchangeRatesFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.exchange_rates_fragment_options, menu);
    final MenuItem searchMenuItem = menu.findItem(R.id.exchange_rates_options_search);
    if (config.isEnableExchangeRates()) {
        final SearchView searchView = (SearchView) searchMenuItem.getActionView();
        searchView.setOnQueryTextListener(new OnQueryTextListener() {

            @Override
            public boolean onQueryTextChange(final String newText) {
                viewModel.setConstraint(Strings.emptyToNull(newText.trim()));
                maybeSubmitList();
                return true;
            }

            @Override
            public boolean onQueryTextSubmit(final String query) {
                searchView.clearFocus();
                return true;
            }
        });
        // Workaround for not being able to style the SearchView
        final int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        final EditText searchInput = searchView.findViewById(id);
        searchInput.setTextColor(activity.getColor(R.color.fg_on_dark_bg_network_significant));
        searchInput.setHintTextColor(activity.getColor(R.color.fg_on_dark_bg_network_insignificant));
    } else {
        searchMenuItem.setVisible(false);
    }
    super.onCreateOptionsMenu(menu, inflater);
}
Also used : EditText(android.widget.EditText) OnQueryTextListener(android.widget.SearchView.OnQueryTextListener) SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem)

Aggregations

SearchView (android.widget.SearchView)72 View (android.view.View)37 TextView (android.widget.TextView)30 MenuItem (android.view.MenuItem)28 ImageView (android.widget.ImageView)16 ListView (android.widget.ListView)15 AdapterView (android.widget.AdapterView)14 RecyclerView (android.support.v7.widget.RecyclerView)12 SearchManager (android.app.SearchManager)11 Test (org.junit.Test)8 Activity (android.app.Activity)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 SettingsActivity (com.android.settings.SettingsActivity)7 MenuInflater (android.view.MenuInflater)6 ViewGroup (android.view.ViewGroup)6 Toolbar (android.widget.Toolbar)6 Intent (android.content.Intent)4 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)4 Nullable (android.support.annotation.Nullable)3