android.support.v7.view.menu.MenuPresenter Java Examples
The following examples show how to use
android.support.v7.view.menu.MenuPresenter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ToolbarHandler.java From NightOwl with Apache License 2.0 | 6 votes |
@Override public void draw(@NonNull View view, @NonNull Object value) { Toolbar toolbar = (Toolbar) view; int themeId = (int) value; try { ActionMenuView actionMenuView = (ActionMenuView) sActionMenuViewField.get(toolbar); if ( actionMenuView == null ){ toolbar.getContext().setTheme(themeId); } else { MenuPresenter presenter = (MenuPresenter) sPresenterField.get(actionMenuView); Context context = (Context) sContextField.get(presenter); context.setTheme(themeId); } } catch (IllegalAccessException e) { e.printStackTrace(); } toolbar.setPopupTheme((Integer) value); }
Example #2
Source File: ToolbarContentTintHelper.java From APlayer with GNU General Public License v3.0 | 5 votes |
public ATHMenuPresenterCallback(Context context, final @ColorInt int color, MenuPresenter.Callback parentCb, Toolbar toolbar) { mContext = context; mColor = color; mParentCb = parentCb; mToolbar = toolbar; }
Example #3
Source File: ToolbarContentTintHelper.java From APlayer with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public static void setToolbarContentColor(@NonNull Context context, Toolbar toolbar, @Nullable Menu menu, final @ColorInt int toolbarContentColor, final @ColorInt int titleTextColor, final @ColorInt int subtitleTextColor, final @ColorInt int menuWidgetColor) { if (toolbar == null) { return; } if (menu == null) { menu = toolbar.getMenu(); } toolbar.setTitleTextColor(titleTextColor); toolbar.setSubtitleTextColor(subtitleTextColor); if (toolbar.getNavigationIcon() != null) { // Tint the toolbar navigation icon (e.g. back, drawer, etc.) toolbar.setNavigationIcon( TintHelper.createTintedDrawable(toolbar.getNavigationIcon(), toolbarContentColor)); } InternalToolbarContentTintUtil.tintMenu(toolbar, menu, toolbarContentColor); InternalToolbarContentTintUtil.applyOverflowMenuTint(context, toolbar, menuWidgetColor); if (context instanceof Activity) { InternalToolbarContentTintUtil .setOverflowButtonColor((Activity) context, toolbarContentColor); } try { // Tint immediate overflow menu items final Field menuField = Toolbar.class.getDeclaredField("mMenuBuilderCallback"); menuField.setAccessible(true); final Field presenterField = Toolbar.class.getDeclaredField("mActionMenuPresenterCallback"); presenterField.setAccessible(true); final Field menuViewField = Toolbar.class.getDeclaredField("mMenuView"); menuViewField.setAccessible(true); final MenuPresenter.Callback currentPresenterCb = (MenuPresenter.Callback) presenterField .get(toolbar); if (!(currentPresenterCb instanceof ATHMenuPresenterCallback)) { final ATHMenuPresenterCallback newPresenterCb = new ATHMenuPresenterCallback(context, menuWidgetColor, currentPresenterCb, toolbar); final MenuBuilder.Callback currentMenuCb = (MenuBuilder.Callback) menuField.get(toolbar); toolbar.setMenuCallbacks(newPresenterCb, currentMenuCb); ActionMenuView menuView = (ActionMenuView) menuViewField.get(toolbar); if (menuView != null) { menuView.setMenuCallbacks(newPresenterCb, currentMenuCb); } } // OnMenuItemClickListener to tint submenu items final Field menuItemClickListener = Toolbar.class .getDeclaredField("mOnMenuItemClickListener"); menuItemClickListener.setAccessible(true); Toolbar.OnMenuItemClickListener currentClickListener = (Toolbar.OnMenuItemClickListener) menuItemClickListener .get(toolbar); if (!(currentClickListener instanceof ATHOnMenuItemClickListener)) { final ATHOnMenuItemClickListener newClickListener = new ATHOnMenuItemClickListener(context, menuWidgetColor, currentClickListener, toolbar); toolbar.setOnMenuItemClickListener(newClickListener); } } catch (Exception e) { e.printStackTrace(); } }