本文整理汇总了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());
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}