Example usage for android.view MenuItem setShowAsActionFlags

List of usage examples for android.view MenuItem setShowAsActionFlags

Introduction

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

Prototype

public MenuItem setShowAsActionFlags(int actionEnum);

Source Link

Document

Sets how this item should display in the presence of an Action Bar.

Usage

From source file:org.mariotaku.twidere.util.MenuUtils.java

public static void setMenuItemShowAsActionFlags(Menu menu, int id, int flags) {
    if (menu == null)
        return;/* w w  w .j av a  2  s .  c o m*/
    final MenuItem item = menu.findItem(id);
    if (item == null)
        return;
    item.setShowAsActionFlags(flags);
    MenuItemCompat.setShowAsAction(item, flags);
}

From source file:org.kosmakoff.pocketreckoner.ui.MainActivity.java

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

    switch (currentMenu) {
    case PEOPLE://w w w  . ja  v  a  2 s  .c om
        MenuItem addPersonMenuItem = menu.add(Menu.NONE, R.id.menu_item_add_person, 10, R.string.add_person);
        addPersonMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
        addPersonMenuItem.setIcon(R.drawable.ic_social_add_person);
        break;
    case CHECKS:
        MenuItem addCheckMenuItem = menu.add(Menu.NONE, R.id.menu_item_add_check, 10, R.string.add_check);
        addCheckMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
        addCheckMenuItem.setIcon(R.drawable.ic_action_new_dark);
        break;
    default:
        break;
    }

    return true;
}

From source file:com.giltesa.taskcalendar.activity.Main.java

/**
 * @param searchItem/*from w  w w . j  a v a  2  s  . com*/
 */
private void setupSearchView(MenuItem searchItem) {
    searchItem.setShowAsActionFlags(
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    mSearchView.setOnQueryTextListener(this);
}

From source file:th.in.ffc.person.visit.VisitEpiActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.edit_add_activity, menu);

    MenuItem item = menu.add(0, R.string.appoint, 2, R.string.appoint);
    item.setIcon(R.drawable.ic_action_epi_appoint);
    item.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return true;//from w  ww  . j a va  2 s .c  o m
}

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

private void setupSearchView(MenuItem searchItem) {

    if (isAlwaysExpanded()) {
        mSearchView.setIconifiedByDefault(false);
    } else {//w  w w  .  ja v  a2 s  . c  om
        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:com.orpheusdroid.screenrecorder.VideosListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem refresh = menu.add("Refresh");
    refresh.setIcon(R.drawable.ic_refresh_white_24dp);
    refresh.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
    refresh.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override/*from ww w  . jav a  2  s .  c  o m*/
        public boolean onMenuItemClick(MenuItem menuItem) {
            // Prevent repeated refresh requests
            if (swipeRefreshLayout.isRefreshing())
                return false;
            videosList.clear();
            checkPermission();
            Log.d(Const.TAG, "Refreshing");
            return false;
        }
    });
}

From source file:com.shafiq.mytwittle.view.BaseLaneActivity.java

protected void configureActionBarSearchView(Menu menu) {

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

    searchItem.setShowAsActionFlags(
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    mSearchView.setOnQueryTextListener(this);

    OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() {

        @Override//from   w ww  .  j a va2  s  .  co m
        public void onFocusChange(View v, boolean hasFocus) {

            mCurrentComposeFragment.setIgnoreFocusChange(true);
            if (mComposeTweetView != null) {
                mComposeTweetView.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            }
            if (mComposeDirectMessageView != null) {
                mComposeDirectMessageView.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            }
            mCurrentComposeFragment.setIgnoreFocusChange(false);
        }

    };

    mSearchView.setOnQueryTextFocusChangeListener(onFocusChangeListener);
    mSearchView.setOnFocusChangeListener(onFocusChangeListener);
}

From source file:com.tweetlanes.android.core.view.BaseLaneActivity.java

void configureActionBarSearchView(Menu menu) {

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

    searchItem.setShowAsActionFlags(
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(this);

    OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() {

        @Override/*from   www . j av a2 s.co m*/
        public void onFocusChange(View v, boolean hasFocus) {

            mCurrentComposeFragment.setIgnoreFocusChange(true);

            if (mComposeTweetView != null) {
                mComposeTweetView.setVisibility(View.GONE);
            }
            if (mComposeDirectMessageView != null) {
                mComposeDirectMessageView.setVisibility(View.GONE);
            }

            if (!hasFocus) {
                if (mCurrentComposeFragment == mComposeDirectMessageFragment) {
                    if (mComposeDirectMessageView != null) {
                        mComposeDirectMessageView.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (mComposeTweetView != null) {
                        mComposeTweetView.setVisibility(View.VISIBLE);
                    }
                }
            }

            mCurrentComposeFragment.setIgnoreFocusChange(false);
        }

    };

    searchView.setOnQueryTextFocusChangeListener(onFocusChangeListener);
    searchView.setOnFocusChangeListener(onFocusChangeListener);
}