Example usage for android.view MenuItem getActionView

List of usage examples for android.view MenuItem getActionView

Introduction

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

Prototype

public View getActionView();

Source Link

Document

Returns the currently set action view for this menu item.

Usage

From source file:com.weebly.opus1269.copyeverywhere.ui.shared.MenuTint.java

/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>/* w  w  w .j  a  va  2 s. com*/
 * <p/>
 * <p>Call this method after inflating/creating your menu in
 * {@link Activity#onCreateOptionsMenu(Menu)}.</p>
 * <p/>
 * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p>
 *
 * @param activity the activity to apply the menu tinting on.
 */
public void apply(final Activity activity) {

    if (forceIcons) {
        forceMenuIcons(menu);
    }

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        colorMenuItem(item, menuItemIconColor, menuItemIconAlpha);
        if (reApplyOnChange) {
            View view = item.getActionView();
            if (view != null) {
                if (item instanceof MenuItemImpl) {
                    ((MenuItemImpl) item)
                            .setSupportOnActionExpandListener(new SupportActionExpandListener(this));
                } else {
                    item.setOnActionExpandListener(new NativeActionExpandListener(this));
                }
            }
        }
    }

    actionBarView = findActionBar(activity);
    if (actionBarView == null) {
        Log.w(TAG, "Could not find the ActionBar");
        return;
    }

    // We must wait for the view to be created to set a color filter on the drawables.
    actionBarView.post(new Runnable() {

        @Override
        public void run() {
            for (int i = 0, size = menu.size(); i < size; i++) {
                MenuItem menuItem = menu.getItem(i);
                if (isInOverflow(menuItem)) {
                    colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha);
                }
                if (menuItem.hasSubMenu()) {
                    SubMenu subMenu = menuItem.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha);
                    }
                }
            }
            if (menuItemIconColor != null || menuItemIconAlpha != null) {
                overflowButton = findOverflowMenuButton(activity, actionBarView);
                colorOverflowMenuItem(overflowButton);
            }
        }
    });
}

From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java

/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>/*www  .  ja v  a  2  s  .c o m*/
 * <p>
 * <p>Call this method after inflating/creating your menu in
 * {@link Activity#onCreateOptionsMenu(Menu)}.</p>
 * <p>
 * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p>
 *
 * @param activity the activity to apply the menu tinting on.
 */
public void apply(final Activity activity) {

    if (menu != null) {
        if (forceIcons) {
            forceMenuIcons(menu);
        }

        for (int i = 0, size = menu.size(); i < size; i++) {
            MenuItem item = menu.getItem(i);
            colorMenuItem(item, iconsColor, iconsAlpha);
            if (reApplyOnChange) {
                View view = item.getActionView();
                if (view != null) {
                    if (item instanceof MenuItemImpl) {
                        ((MenuItemImpl) item)
                                .setSupportOnActionExpandListener(new SupportActionExpandListener(this));
                    } else {
                        item.setOnActionExpandListener(new NativeActionExpandListener(this));
                    }
                }
            }
        }
    }

    actionBarView = findActionBar(activity);
    if (actionBarView == null) {
        Log.w(TAG, "Could not find the ActionBar");
        return;
    }

    // We must wait for the view to be created to set a color filter on the drawables.
    actionBarView.post(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < actionBarView.getChildCount(); i++) {
                final View v = actionBarView.getChildAt(i);

                //Step 1 : Changing the color of back button (or open drawer button).
                if (v instanceof ImageButton) {
                    //Action Bar back button
                    ((ImageButton) v).getDrawable()
                            .setColorFilter(new PorterDuffColorFilter(iconsColor, PorterDuff.Mode.SRC_ATOP));
                }
            }
            if (menu != null) {
                for (int i = 0, size = menu.size(); i < size; i++) {
                    MenuItem menuItem = menu.getItem(i);
                    if (isInOverflow(menuItem)) {
                        colorMenuItem(menuItem, iconsColor, iconsAlpha);
                    }
                    if (menuItem.hasSubMenu()) {
                        SubMenu subMenu = menuItem.getSubMenu();
                        for (int j = 0; j < subMenu.size(); j++) {
                            colorMenuItem(subMenu.getItem(j), iconsColor, iconsAlpha);
                        }
                    }
                }
                if (iconsColor != null) {
                    overflowButton = findOverflowMenuButton(activity, actionBarView);
                    colorOverflowMenuItem(overflowButton);
                }
            }
        }
    });
}

From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>/*from  ww  w. j a  v a  2s .  co m*/
 * <p/>
 * <p>Call this method after inflating/creating your menu in
 * {@link Activity#onCreateOptionsMenu(Menu)}.</p>
 * <p/>
 * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p>
 *
 * @param activity the activity to apply the menu tinting on.
 */
public void apply(final Activity activity) {

    if (forceIcons) {
        forceMenuIcons(menu);
    }

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        colorMenuItem(item, menuItemIconColor, menuItemIconAlpha);
        if (reApplyOnChange) {
            View view = item.getActionView();
            if (view != null) {
                if (item instanceof MenuItemImpl) {
                    ((MenuItemImpl) item)
                            .setSupportOnActionExpandListener(new SupportActionExpandListener(this));
                } else {
                    item.setOnActionExpandListener(new NativeActionExpandListener(this));
                }
            }
        }
    }

    actionBarView = findActionBar(activity);
    if (actionBarView == null) {
        Log.w(LOG_TAG, "Could not find the ActionBar");
        return;
    }

    // We must wait for the view to be created to set a color filter on the drawables.
    actionBarView.post(new Runnable() {

        @Override
        public void run() {
            for (int i = 0, size = menu.size(); i < size; i++) {
                MenuItem menuItem = menu.getItem(i);
                if (isInOverflow(menuItem)) {
                    colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha);
                }
                if (menuItem.hasSubMenu()) {
                    SubMenu subMenu = menuItem.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha);
                    }
                }
            }
            if (menuItemIconColor != null || menuItemIconAlpha != null) {
                overflowButton = findOverflowMenuButton(activity, actionBarView);
                colorOverflowMenuItem(overflowButton);
            }
        }
    });
}

From source file:ua.com.spacetv.mycookbook.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override/* ww w  .  j  a v a2 s  . co  m*/
        public boolean onQueryTextSubmit(String query) {
            if (query.length() > 1) {
                String tag = FragListRecipe.class.getSimpleName();
                tag += "Search";
                Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag);
                if (fragment == null) {
                    mFragmentHelper.attachListRecipeFragment(0, MODE_SEARCH_RESULT, query);
                } else {
                    FragListRecipe.setParams(0, MODE_SEARCH_RESULT, query);
                    new FragListRecipe().showListRecipe();
                }

            } else
                Snackbar.make(searchView, R.string.text_empty_request, Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    };

    searchView.setOnQueryTextListener(queryTextListener);
    return true;
}

From source file:org.wheelmap.android.activity.MainMultiPaneActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean b = onOptionItemClicked(item.getItemId(), item.getActionView(), item);
    return b ? b : super.onOptionsItemSelected(item);
}

From source file:me.barrasso.android.volume.activities.ConfigurationActivity.java

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

    // Get the action view used in your switch item
    final MenuItem toggle = menu.findItem(R.id.action_switch);
    if (null != toggle) {
        switchView = (CompoundButton) toggle.getActionView().findViewById(R.id.switch_view);
        if (null != switchView) {
            switchView.setChecked(VolumeAccessibilityService.isEnabled(this));
            switchView.setOnCheckedChangeListener(this);
        }/*from   w  ww  . ja v  a2 s.  c  o m*/
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:me.barrasso.android.volume.activities.ConfigurationActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
    bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
    bar.setTitle(getTitle());//ww w .j  a va2s  .c om
    bar.inflateMenu(R.menu.toggle_switch);
    final MenuItem toggle = bar.getMenu().findItem(R.id.action_switch);
    if (null != toggle) {
        switchView = (CompoundButton) toggle.getActionView().findViewById(R.id.switch_view);
        if (null != switchView) {
            switchView.setChecked(VolumeAccessibilityService.isEnabled(this));
            switchView.setOnCheckedChangeListener(this);
        }
    }
    if (isTaskRoot())
        bar.setNavigationIcon(null);
    root.addView(bar, 0);
    bar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

From source file:de.spiritcroc.ownlog.ui.fragment.LogFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.fragment_log, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    searchItem.setOnActionExpandListener(mSearchActionExpandListener);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setOnQueryTextListener(mSearchQueryTextListener);
    mSearchView.setOnQueryTextFocusChangeListener(mSearchQueryTextFocusChangeListener);
}

From source file:com.teitsmch.hearthmaker.MainActivity.java

private void rotate(MenuItem item) {
    Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate);
    rotation.setFillAfter(true);/*w  w w .j  av  a 2 s  .  co m*/
    item.getActionView().startAnimation(rotation);
}

From source file:com.dm.wallpaper.board.fragments.CategoryWallpapersFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_wallpaper_search_sort, menu);
    MenuItem search = menu.findItem(R.id.menu_search);
    MenuItem sort = menu.findItem(R.id.menu_sort);

    int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon);
    search.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_search, color));
    sort.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_sort, color));

    mSearchView = (SearchView) search.getActionView();
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_SEARCH);
    mSearchView.setQueryHint(getActivity().getResources().getString(R.string.menu_search));
    mSearchView.setMaxWidth(Integer.MAX_VALUE);

    ViewHelper.setSearchViewTextColor(mSearchView, color);
    ViewHelper.setSearchViewBackgroundColor(mSearchView, Color.TRANSPARENT);
    ViewHelper.setSearchViewCloseIcon(mSearchView,
            DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_close, color));
    ViewHelper.setSearchViewSearchIcon(mSearchView, null);

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override/*from w ww  .  ja  va  2s  .co  m*/
        public boolean onQueryTextChange(String string) {
            filterSearch(string);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String string) {
            mSearchView.clearFocus();
            return true;
        }
    });
}