当前位置: 首页>>代码示例>>Java>>正文


Java Toolbar.getMenu方法代码示例

本文整理汇总了Java中android.support.v7.widget.Toolbar.getMenu方法的典型用法代码示例。如果您正苦于以下问题:Java Toolbar.getMenu方法的具体用法?Java Toolbar.getMenu怎么用?Java Toolbar.getMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.Toolbar的用法示例。


在下文中一共展示了Toolbar.getMenu方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inflateToolbarMenu

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
 * Inflates the menu of the toolbar, which is shown, when the tab switcher is shown.
 */
private void inflateToolbarMenu() {
    Toolbar[] toolbars = getToolbars();
    int menuId = getModel().getToolbarMenuId();

    if (toolbars != null && menuId != -1) {
        Toolbar toolbar = toolbars.length > 1 ? toolbars[TabSwitcher.SECONDARY_TOOLBAR_INDEX] :
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX];
        Menu previousMenu = toolbar.getMenu();

        if (previousMenu != null) {
            previousMenu.clear();
        }

        toolbar.inflateMenu(menuId);
        toolbar.setOnMenuItemClickListener(getModel().getToolbarMenuItemListener());
    }
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:21,代码来源:AbstractTabSwitcherLayout.java

示例2: getToolbarMenu

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Nullable
@Override
public final Menu getToolbarMenu() {
    Toolbar[] toolbars = getToolbars();

    if (toolbars != null) {
        Toolbar toolbar = toolbars.length > 1 ? toolbars[TabSwitcher.SECONDARY_TOOLBAR_INDEX] :
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX];
        return toolbar.getMenu();
    }

    return null;
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:14,代码来源:AbstractTabSwitcherLayout.java

示例3: tintMenu

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu, final @ColorInt int color) {
    try {
        final Field field = Toolbar.class.getDeclaredField("mCollapseIcon");
        field.setAccessible(true);
        Drawable collapseIcon = (Drawable) field.get(toolbar);
        if (collapseIcon != null) {
            field.set(toolbar, TintHelper.createTintedDrawable(collapseIcon, color));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // credits: https://snow.dog/blog/how-to-dynamicaly-change-android-toolbar-icons-color/
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        final View v = toolbar.getChildAt(i);
        // We can't iterate through the toolbar.getMenu() here, because we need the ActionMenuItemView. ATEActionMenuItemView is overriding the item icon tint color.
        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    int drawablesCount = ((ActionMenuItemView) innerView).getCompoundDrawables().length;
                    for (int k = 0; k < drawablesCount; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            ((ActionMenuItemView) innerView).getCompoundDrawables()[k].setColorFilter(colorFilter);
                        }
                    }
                }
            }
        }
    }

    if (menu == null)
        menu = toolbar.getMenu();
    if (menu != null && menu.size() > 0) {
        for (int i = 0; i < menu.size(); i++) {
            final MenuItem item = menu.getItem(i);
            // We must iterate through the toolbar.getMenu() too, to keep the tint when resuming the paused activity.
            if (item.getIcon() != null) {
                item.setIcon(TintHelper.createTintedDrawable(item.getIcon(), color));
            }
            // Search view theming
            if (item.getActionView() != null && (item.getActionView() instanceof android.widget.SearchView || item.getActionView() instanceof android.support.v7.widget.SearchView)) {
                SearchViewTintUtil.setSearchViewContentColor(item.getActionView(), color);
            }
        }
    }
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:50,代码来源:ToolbarProcessor.java

示例4: getToolbarMenu

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Nullable
@Override
public final Menu getToolbarMenu() {
    Toolbar[] toolbars = getToolbars();

    if (toolbars != null) {
        Toolbar toolbar = toolbars.length > 1 ? toolbars[1] : toolbars[0];
        return toolbar.getMenu();
    }

    return null;
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:13,代码来源:AbstractTabSwitcherLayout.java


注:本文中的android.support.v7.widget.Toolbar.getMenu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。