@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); } } } }
/** * It's important to set overflowDescription atribute in styles, so we can grab the reference * to the overflow icon. Check: res/values/styles.xml * * @param activity * @param colorFilter */ private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) { final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, overflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } final ActionMenuView overflowViewParent = (ActionMenuView) outViews.get(0).getParent(); overflowViewParent.getOverflowIcon().setColorFilter(colorFilter); removeOnGlobalLayoutListener(decorView, this); } }); }
private void onGlobalLayout() { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener); else mToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(mOnGlobalLayoutListener); ActionMenuView menuView = getMenuView(); for(int i = 0, count = menuView == null ? 0 : menuView.getChildCount(); i < count; i++){ View child = menuView.getChildAt(i); if(mRippleStyle != 0){ if(child.getBackground() == null || !(child.getBackground() instanceof ToolbarRippleDrawable)) ViewUtil.setBackground(child, getBackground()); } } if(mGroupChanged){ animateIn(); mGroupChanged = false; } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { ActionMenuView actionMenuView = ((ListHolderActivity) getActivity()).getActionMenuView(); Menu actionMenu = actionMenuView.getMenu(); actionMenu.clear(); actionMenuView.setVisibility(View.GONE); inflater.inflate(R.menu.main, menu); MenuItem item = menu.add(1, 1001, 1, getString(R.string.grid_carousel)); if (carousel) { item.setIcon(R.drawable.gridview); } else { item.setIcon(R.drawable.carousel); } MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); actionMenuView.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { return onOptionsItemSelected(menuItem); } }); }
public void showOverflowPrompt(View view) { final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this) .setPrimaryText(R.string.overflow_prompt_title) .setSecondaryText(R.string.overflow_prompt_description) .setAnimationInterpolator(new FastOutSlowInInterpolator()) .setMaxTextWidth(R.dimen.tap_target_menu_max_width) .setIcon(R.drawable.ic_more_vert); final Toolbar tb = this.findViewById(android.support.v7.appcompat.R.id.action_bar); final View child = tb.getChildAt(2); if (child instanceof ActionMenuView) { final ActionMenuView actionMenuView = ((ActionMenuView) child); tapTargetPromptBuilder.setTarget(actionMenuView.getChildAt(actionMenuView.getChildCount() - 1)); } else { Toast.makeText(this, R.string.overflow_unavailable, Toast.LENGTH_SHORT); } tapTargetPromptBuilder.show(); }
public void showOverflowPrompt(View view) { final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this) .setPrimaryText(R.string.overflow_prompt_title) .setSecondaryText(R.string.overflow_prompt_description) .setAnimationInterpolator(new FastOutSlowInInterpolator()) .setMaxTextWidth(R.dimen.tap_target_menu_max_width) .setIcon(R.drawable.ic_more_vert); final Toolbar tb = this.findViewById(R.id.toolbar); final View child = tb.getChildAt(2); if (child instanceof ActionMenuView) { final ActionMenuView actionMenuView = ((ActionMenuView) child); tapTargetPromptBuilder.setTarget(actionMenuView.getChildAt(actionMenuView.getChildCount() - 1)); } else { Toast.makeText(this, R.string.overflow_unavailable, Toast.LENGTH_SHORT); } tapTargetPromptBuilder.show(); }
public void showStylePrompt(View view) { final MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(this, R.style.MaterialTapTargetPromptTheme_FabTarget); final Toolbar tb = this.findViewById(R.id.toolbar); final View child = tb.getChildAt(2); if (child instanceof ActionMenuView) { final ActionMenuView actionMenuView = ((ActionMenuView) child); builder.setTarget(actionMenuView.getChildAt(actionMenuView.getChildCount() - 1)); } else { Toast.makeText(this, R.string.overflow_unavailable, Toast.LENGTH_SHORT); } builder.setIcon(R.drawable.ic_more_vert) .show(); }
public void showOverflowPrompt(View view) { final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this) .setPrimaryText(R.string.overflow_prompt_title) .setSecondaryText(R.string.overflow_prompt_description) .setAnimationInterpolator(new FastOutSlowInInterpolator()) .setMaxTextWidth(R.dimen.max_prompt_width) .setIcon(R.drawable.ic_more_vert) .setClipToView(findViewById(R.id.dialog_view)); final Toolbar tb = this.findViewById(R.id.toolbar); final View child = tb.getChildAt(2); if (child instanceof ActionMenuView) { final ActionMenuView actionMenuView = ((ActionMenuView) child); tapTargetPromptBuilder.setTarget(actionMenuView.getChildAt(actionMenuView.getChildCount() - 1)); } else { Toast.makeText(this, R.string.overflow_unavailable, Toast.LENGTH_SHORT); } tapTargetPromptBuilder.show(); }
private static ImageView findOverflowMenuButton(Activity activity, ViewGroup viewGroup) { if (viewGroup == null) { return null; } ImageView overflow = null; for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) { View v = viewGroup.getChildAt(i); if (v instanceof ImageView && (v.getClass().getSimpleName().equals("OverflowMenuButton") || v instanceof ActionMenuView.ActionMenuChildView)) { overflow = (ImageView) v; } else if (v instanceof ViewGroup) { overflow = findOverflowMenuButton(activity, (ViewGroup) v); } if (overflow != null) { break; } } return overflow; }
public final View a(xp paramxp, View paramView, ViewGroup paramViewGroup) { View localView = paramxp.getActionView(); if ((localView == null) || (paramxp.f())) { localView = super.a(paramxp, paramView, paramViewGroup); } if (paramxp.isActionViewExpanded()) {} for (int i1 = 8;; i1 = 0) { localView.setVisibility(i1); ActionMenuView localActionMenuView = (ActionMenuView)paramViewGroup; ViewGroup.LayoutParams localLayoutParams = localView.getLayoutParams(); if (!localActionMenuView.checkLayoutParams(localLayoutParams)) { localView.setLayoutParams(localActionMenuView.a(localLayoutParams)); } return localView; } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_note, container, false); ButterKnife.bind(this, v); mEditTools.setTitle(null); getActivity().getMenuInflater().inflate(R.menu.menu_note_toolbar, mEditToolsMenu.getMenu()); mEditToolsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); return v; }
@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); }
@Override public boolean onPrepareOptionsMenu(Menu menu) { //fixing toolbar icons after changing theme //should be fixed in next support release Toolbar t = (Toolbar) findViewById(R.id.toolbar); for (int i = 0; i < t.getChildCount(); i++) { if (t.getChildAt(i) instanceof ActionMenuView) { ActionMenuView v = (ActionMenuView) t.getChildAt(i); for (int j = 0; j < v.getChildCount(); j++) { if (v.getChildAt(j) instanceof TintImageView) { TintImageView v1 = (TintImageView) v.getChildAt(j); v1.setImageResource(R.drawable.abc_ic_menu_moreoverflow_mtrl_alpha); } } } } return super.onPrepareOptionsMenu(menu); }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { ActionMenuView actionMenuView = ((ListHolderActivity) getActivity()).getActionMenuView(); Menu actionMenu = actionMenuView.getMenu(); actionMenu.clear(); actionMenuView.setVisibility(View.VISIBLE); inflater.inflate(R.menu.main, actionMenuView.getMenu()); MenuItem item = actionMenu.add(1, 1001, 1, getString(R.string.grid_carousel)); if (carousel) { item.setIcon(R.drawable.gridview); } else { item.setIcon(R.drawable.carousel); } MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); actionMenuView.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { return onOptionsItemSelected(menuItem); } }); }
/** * Get the list of visible MenuItems * * @param toolbar * @return the list of visible MenuItems */ public static List<MenuItem> getVisibleMenuItemList(@NonNull Toolbar toolbar) { List<MenuItem> list = new ArrayList<>(); for (int i = 0; i < toolbar.getChildCount(); i++) { final View v = toolbar.getChildAt(i); if (v instanceof ActionMenuView) { int childCount = ((ActionMenuView) v).getChildCount(); for (int j = 0; j < childCount; j++) { final View innerView = ((ActionMenuView) v).getChildAt(j); if (innerView instanceof ActionMenuItemView) { list.add(((ActionMenuItemView) innerView).getItemData()); } } } } return list; }
/** * Search for a particular menu * * @param toolbar * @param menuId * @return the corresponding MenuItem, or null if not found */ public static MenuItem getMenuItem(@NonNull Toolbar toolbar, @IdRes int menuId) { View v; int childCount; View innerView; MenuItem menuItem; for (int i = 0; i < toolbar.getChildCount(); i++) { v = toolbar.getChildAt(i); if (v instanceof ActionMenuView) { childCount = ((ActionMenuView) v).getChildCount(); for (int j = 0; j < childCount; j++) { innerView = ((ActionMenuView) v).getChildAt(j); if (innerView instanceof ActionMenuItemView) { menuItem = ((ActionMenuItemView) innerView).getItemData(); if (menuItem.getItemId() == menuId) { return menuItem; } } } } } return null; }
@Override public boolean onCreateActionMode(final ActionMode mode, Menu menu) { // Show contextual action bars to start/stop/remove/etc. torrents in batch mode if (actionsMenu == null) { actionsMenu = ((TorrentsActivity) getActivity()).contextualMenu; actionsToolbar = ((TorrentsActivity) getActivity()).actionsToolbar; addmenuButton = ((TorrentsActivity) getActivity()).addmenuButton; } actionsToolbar.setEnabled(false); actionsMenu.setVisibility(View.VISIBLE); addmenuButton.setVisibility(View.GONE); actionsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { return onActionItemClicked(mode, menuItem); } }); actionsMenu.getMenu().clear(); getActivity().getMenuInflater().inflate(R.menu.fragment_torrents_cab, actionsMenu.getMenu()); Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); selectionManagerMode = new SelectionManagerMode(themedContext, torrentsList, R.plurals.navigation_torrentsselected); selectionManagerMode.onCreateActionMode(mode, menu); return true; }
@Override public boolean onCreateActionMode(final ActionMode mode, Menu menu) { // Show contextual action bar to start/stop/remove/etc. torrents in batch mode detailsMenu.setEnabled(false); contextualMenu.setVisibility(View.VISIBLE); contextualMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { return onActionItemClicked(mode, menuItem); } }); contextualMenu.getMenu().clear(); getActivity().getMenuInflater().inflate(R.menu.fragment_details_cab_main, contextualMenu.getMenu()); Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); mode.getMenuInflater().inflate(R.menu.fragment_details_cab_secondary, menu); selectionManagerMode = new SelectionManagerMode(themedContext, detailsList, R.plurals.navigation_filesselected); selectionManagerMode.setOnlyCheckClass(TorrentFile.class); selectionManagerMode.onCreateActionMode(mode, menu); return true; }
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor) { final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY); for(int i = 0; i < toolbarView.getChildCount(); i++) { final View v = toolbarView.getChildAt(i); if(v instanceof ImageButton) { ((ImageButton)v).getDrawable().setColorFilter(colorFilter); } 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) { final int finalK = k; innerView.post(new Runnable() { @Override public void run() { ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter); } }); } } } } } } }
public FloatingSearchView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); if (isInEditMode()) { mActivity = null; } else { mActivity = getActivity(); } setFocusable(true); setFocusableInTouchMode(true); inflate(getContext(), R.layout.fsv_floating_search_layout, this); mSearchInput = (LogoEditText)findViewById(R.id.fsv_search_text); mNavButtonView = (ImageView) findViewById(R.id.fsv_search_action_navigation); mRecyclerView = (RecyclerView) findViewById(R.id.fsv_suggestions_list); mDivider = findViewById(R.id.fsv_suggestions_divider); mSearchContainer = (ViewGroup) findViewById(R.id.fsv_search_container); mActionMenu = (ActionMenuView) findViewById(R.id.fsv_search_action_menu); //TODO: move elevation parameters to XML attributes mSearchBackground = new RoundRectDrawableWithShadow( DEFAULT_CONTENT_COLOR, ViewUtils.dpToPx(DEFAULT_RADIUS), ViewUtils.dpToPx(DEFAULT_ELEVATION), ViewUtils.dpToPx(DEFAULT_MAX_ELEVATION)); mSearchBackground.setAddPaddingForCorners(true); mCardDecorator = new SuggestionItemDecorator(mSearchBackground.mutate()); applyXmlAttributes(attrs, defStyleAttr, 0); setupViews(); }
private void animateIn(){ ActionMenuView menuView = getMenuView(); for(int i = 0, count = menuView == null ? 0 : menuView.getChildCount(); i < count; i++){ View child = menuView.getChildAt(i); Animation anim = mAnimator.getInAnimation(child, i); if(anim != null) child.startAnimation(anim); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); ActionMenuView actionMenuView = ((ListHolderActivity) getActivity()).getActionMenuView(); actionMenuView.getMenu().clear(); MenuItem add = menu.add(1, ADD_CHANNEL, 0, R.string.add_channel); add.setIcon(R.drawable.ic_menu_add); MenuItemCompat.setShowAsAction(add, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); /*if (Build.VERSION.SDK_INT < 14) { preferences.edit().putInt("player_type", 1).commit(); actionMenuView.setVisibility(View.GONE); } else { actionMenuView.setVisibility(View.VISIBLE); int currentPlayer = preferences.getInt("player_type", 0); Menu actionMenu = actionMenuView.getMenu(); MenuItem player = actionMenu.add(1, PLAYER_TYPE, 1, getResources().getStringArray(R.array.player_types)[currentPlayer]); MenuItemCompat.setShowAsAction(player, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); actionMenuView.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { return onOptionsItemSelected(menuItem); } }); }*/ }
private void initActionBar() { mIsTestFile= true; mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); mActionMenuView = (ActionMenuView) findViewById(R.id.actionMenuView); if (mActionMenuView != null) { mActionMenuView.setVisibility(View.GONE); } Log.d("BINH", "initActionBar() called with: " + ""); }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); ActionMenuView actionMenuView = ((ListHolderActivity) getActivity()).getActionMenuView(); Menu actionMenu = actionMenuView.getMenu(); actionMenu.clear(); actionMenuView.setVisibility(View.GONE); }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { ActionMenuView actionMenuView = ((ListHolderActivity) getActivity()).getActionMenuView(); Menu actionMenu = actionMenuView.getMenu(); actionMenu.clear(); actionMenuView.setVisibility(View.GONE); inflater.inflate(R.menu.main, menu); actionMenuView.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { return onOptionsItemSelected(menuItem); } }); }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); ActionMenuView actionMenuView = ((ListHolderActivity) getActivity()).getActionMenuView(); Menu actionMenu = actionMenuView.getMenu(); actionMenu.clear(); actionMenuView.setVisibility(View.GONE); MenuItem item = menu.add(1, REFRESH, 0, R.string.refresh); item.setIcon(R.drawable.ic_menu_refresh); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); menu.clear(); Activity activity = getActivity(); ActionMenuView actionMenuView = ((ListHolderActivity) activity).getActionMenuView(); Menu actionMenu = actionMenuView.getMenu(); actionMenu.clear(); actionMenuView.setVisibility(View.GONE); /* MenuItem truePicker = actionMenu.add(1, 1011, 1, R.string.truepicker); LayoutInflater layoutInflater = activity.getLayoutInflater(); View truePickerView = layoutInflater.inflate(R.layout.truepicker_logo, null, false); truePickerView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent; intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://truepicker.com/")); startActivity(intent); } }); MenuItemCompat.setActionView(truePicker, truePickerView); MenuItemCompat.setShowAsAction(truePicker, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); truePicker.setIcon(R.drawable.truepicker_logo);*/ actionMenuView.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { return onOptionsItemSelected(menuItem); } }); }
public FloatingSearchView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); mActivity = getActivity(); setFocusable(true); setFocusableInTouchMode(true); inflate(getContext(), R.layout.fsv_floating_search_layout, this); mSearchInput = (LogoEditText) findViewById(R.id.fsv_search_text); mNavButtonView = (ImageView) findViewById(R.id.fsv_search_action_navigation); mRecyclerView = (RecyclerView) findViewById(R.id.fsv_suggestions_list); mDivider = findViewById(R.id.fsv_suggestions_divider); mSearchContainer = (ViewGroup) findViewById(R.id.fsv_search_container); mActionMenu = (ActionMenuView) findViewById(R.id.fsv_search_action_menu); //TODO: move elevation parameters to XML attributes mSearchBackground = new RoundRectDrawableWithShadow( DEFAULT_CONTENT_COLOR, ViewUtils.dpToPx(DEFAULT_RADIUS), ViewUtils.dpToPx(DEFAULT_ELEVATION), ViewUtils.dpToPx(DEFAULT_MAX_ELEVATION)); mSearchBackground.setAddPaddingForCorners(true); mCardDecorator = new SuggestionItemDecorator(mSearchBackground.mutate()); applyXmlAttributes(attrs, defStyleAttr, 0); setupViews(); }
public static void applyOverflow(final @NonNull Activity activity, final @Nullable String key, final @Nullable Toolbar toolbar) { if (toolbar == null) return; toolbar.post(new Runnable() { @Override public void run() { try { Field f1 = Toolbar.class.getDeclaredField("mMenuView"); f1.setAccessible(true); ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar); Field f2 = ActionMenuView.class.getDeclaredField("mPresenter"); f2.setAccessible(true); // Actually ActionMenuPresenter BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView); Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup"); f3.setAccessible(true); MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter); setTintForMenuPopupHelper(activity, overflowMenuPopupHelper, key); Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup"); f4.setAccessible(true); MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter); setTintForMenuPopupHelper(activity, subMenuPopupHelper, key); } catch (Exception e) { e.printStackTrace(); } } }); }
@Override public void onViewAdded(View child) { super.onViewAdded(child); if (child instanceof ActionMenuView) { actionMenuView = (ActionMenuView) child; } }
private void setButtonTextColor() { final ActionMenuView buttonsContainer = ViewUtils.findChildByClass(this, ActionMenuView.class); if (buttonsContainer != null) { for (int i = 0; i < buttonsContainer.getChildCount(); i++) { if (buttonsContainer.getChildAt(i) instanceof TextView) { ((TextView) buttonsContainer.getChildAt(i)).setTextColor(getButton(i).getColor().getColor()); } } } }