Example usage for android.view MenuItem SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

List of usage examples for android.view MenuItem SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

Introduction

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

Prototype

int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

To view the source code for android.view MenuItem SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.

Click Source Link

Document

This item's action view collapses to a normal menu item.

Usage

From source file:com.example.ward.view.CursorFragment.java

@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);/*ww  w.j a v  a  2 s .co m*/
}

From source file:org.codecyprus.android_client.ui.ActivityCategories.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(R.string.REFRESH)/* w  w  w.ja  v  a  2 s.c om*/
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    return true;
}

From source file:de.appetites.android.menuItemSearchAction.MenuItemSearchAction.java

private void createMenuItem(Menu menu, Drawable drawable, final LinearLayout list) {
    ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    setLayoutParams(layoutParams);/*  www . j a v  a  2  s  . c om*/

    setHint(R.string.menu_item_search_action_hint);

    searchItem = menu.add(R.string.menu_item_search_action_menu_text).setIcon(drawable);
    searchItem.setActionView(this).setTitle("Search");
    searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            // open keyboard
            list.setVisibility(View.VISIBLE);
            MenuItemSearchAction.this.setText("");
            MenuItemSearchAction.this.requestFocus();

            MenuItemSearchAction.this.postDelayed(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) context
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                }
            }, 200);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // close keyboard
            list.setVisibility(View.GONE);
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(MenuItemSearchAction.this.getWindowToken(), 0);

            return true;
        }
    });

    setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // perform Search
                searchPerformListener.performSearch(MenuItemSearchAction.this.getText().toString());

                searchItem.collapseActionView();
                return true;
            }
            return false;
        }
    });
}

From source file:com.misczak.joinmybridge.EventFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem item = menu.add("Search");
    item.setIcon(R.drawable.ic_search_white_24dp);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    mSearchView = new MySearchView(getActivity());
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setOnCloseListener(this);
    mSearchView.setIconifiedByDefault(true);
    item.setActionView(mSearchView);/*from ww w .j a  va2 s . com*/
}

From source file:ru.piter.fm.activities.RadioActivity.java

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {

    menu.add(0, 1, 1, R.string.ac_refresh).setIcon(R.drawable.ic_navigation_refresh)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.add(0, 2, 2, R.string.ac_settings).setIcon(R.drawable.ic_action_settings)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.add(0, 3, 3, R.string.ac_search).setIcon(R.drawable.ic_action_search)
            .setActionView(R.layout.action_search)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    menu.add(0, 4, 4, R.string.ac_exit).setIcon(R.drawable.ic_cancel)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return super.onCreateOptionsMenu(menu);
}

From source file:de.stadtrallye.rallyesoft.fragments.ChatroomFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem refreshMenuItem = menu.add(Menu.NONE, R.id.refresh_menu, 30, R.string.refresh);

    refreshMenuItem.setIcon(R.drawable.ic_refresh_light);
    refreshMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    MenuItem pictureMenuItem = menu.add(Menu.NONE, R.id.picture_menu, 10, R.string.take_picture);

    pictureMenuItem.setIcon(R.drawable.ic_camera_light);
    pictureMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

From source file:quarkstar.android.javainterviewquestions.MainActivity.java

private void setupSearchView(MenuItem searchItem) {

    if (isAlwaysExpanded()) {
        mSearchView.setIconifiedByDefault(false);
    } else {//w ww .j  a va  2 s.  com
        searchItem.setShowAsActionFlags(
                MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    }

    /*        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            if (searchManager != null) {
    List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
             
    SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
    for (SearchableInfo inf : searchables) {
        if (inf.getSuggestAuthority() != null
                && inf.getSuggestAuthority().startsWith("applications")) {
            info = inf;
        }
    }
    mSearchView.setSearchableInfo(info);
            }
    */
    mSearchView.setOnQueryTextListener(this);
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.xml, menu);/*ww  w.j  a  va2 s. com*/

    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.codecyprus.android_client.ui.ActivityStartQuiz.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(R.string.ENTER_CODE)//from   w w  w  . j a va2  s . c o  m
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    return true;
}

From source file:org.catnut.fragment.TimelineFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.add(Menu.NONE, R.id.refresh, Menu.NONE, R.string.refresh)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); // prefer actionbar refresh
    menu.add(Menu.NONE, R.id.action_back_top, Menu.NONE, getString(R.string.back_to_top))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    // ??/*from   w ww .ja  v a 2s . c  o  m*/
    MenuItem search = menu.add(android.R.string.search_go);
    search.setIcon(R.drawable.ic_title_search_default);
    search.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    mSearchView = VividSearchView.getSearchView(getActivity());
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setOnCloseListener(this);
    search.setActionView(mSearchView);
}