Example usage for android.view MenuItem.OnActionExpandListener MenuItem.OnActionExpandListener

List of usage examples for android.view MenuItem.OnActionExpandListener MenuItem.OnActionExpandListener

Introduction

In this page you can find the example usage for android.view MenuItem.OnActionExpandListener MenuItem.OnActionExpandListener.

Prototype

MenuItem.OnActionExpandListener

Source Link

Usage

From source file:net.ustyugov.jtalk.activity.XMLConsole.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.xml, menu);//from  w  ww  .j av a2  s.  c  o m

    MenuItem.OnActionExpandListener listener = new MenuItem.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            searchString = "";
            updateList();
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }
    };

    SearchView searchView = new SearchView(this);
    searchView.setQueryHint(getString(android.R.string.search_go));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            searchString = query;
            updateList();
            return true;
        }
    });

    MenuItem item = menu.findItem(R.id.search);
    item.setActionView(searchView);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    item.setOnActionExpandListener(listener);
    return super.onCreateOptionsMenu(menu);
}

From source file:org.jitsi.android.gui.contactlist.ContactListFragment.java

/**
 * Invoked when the options menu is created. Creates our own options menu
 * from the corresponding xml./* w w  w.  ja  v  a 2 s. c om*/
 *
 * @param menu the options menu
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    super.onCreateOptionsMenu(menu, menuInflater);

    Activity activity = getActivity();

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);

    this.searchItem = menu.findItem(R.id.search);

    // OnActionExpandListener not supported prior API 14
    if (AndroidUtils.hasAPI(14)) {
        searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                filterContactList("");

                return true; // Return true to collapse action view
            }

            public boolean onMenuItemActionExpand(MenuItem item) {
                return true; // Return true to expand action view
            }
        });
    }

    if (AndroidUtils.hasAPI(11)) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));

        int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = (TextView) searchView.findViewById(id);
        textView.setTextColor(getResources().getColor(R.color.white));
        textView.setHintTextColor(getResources().getColor(R.color.white));

        bindSearchListener();
    }
}