public class MenuTintHelper
extends java.lang.Object
Apply colors and/or transparency to menu icons in a Menu
.
Example usage:
public boolean onCreateOptionsMenu(Menu menu) { ... int color = getResources().getColor(R.color.your_awesome_color); int alpha = 204; // 80% transparency MenuTintHelper.on(menu).setMenuItemIconColor(color).setMenuItemIconAlpha(alpha).apply(this); ... }
Modifier and Type | Class and Description |
---|---|
static class |
MenuTintHelper.Builder |
static class |
MenuTintHelper.NativeActionExpandListener |
static class |
MenuTintHelper.SearchViewFocusListener
Auto collapses the SearchView when the soft keyboard is dismissed.
|
Modifier and Type | Field and Description |
---|---|
private android.view.ViewGroup |
actionBarView |
private boolean |
forceIcons |
private android.view.Menu |
menu |
private java.lang.Integer |
menuItemIconAlpha |
private java.lang.Integer |
menuItemIconColor |
private static java.lang.reflect.Method |
nativeIsActionButton |
private java.lang.Integer |
originalMenuItemIconColor |
private android.widget.ImageView |
overflowButton |
private java.lang.Integer |
overflowDrawableId |
private boolean |
reApplyOnChange |
private java.lang.Integer |
subMenuIconAlpha |
private java.lang.Integer |
subMenuIconColor |
private static java.lang.String |
TAG |
Modifier | Constructor and Description |
---|---|
private |
MenuTintHelper(MenuTintHelper.Builder builder) |
Modifier and Type | Method and Description |
---|---|
void |
apply(android.app.Activity activity)
Sets a ColorFilter and/or alpha on all the
MenuItem s in the
menu, including the OverflowMenuButton. |
static void |
colorIcons(android.app.Activity activity,
android.view.Menu menu,
int color)
Apply a ColorFilter with the specified color to all icons in the menu.
|
static void |
colorMenuItem(android.view.MenuItem menuItem,
java.lang.Integer color,
java.lang.Integer alpha)
Sets the color filter and/or the alpha transparency on a
MenuItem 's
icon. |
private void |
colorOverflowMenuItem(android.widget.ImageView overflow) |
private static android.view.ViewGroup |
findActionBar(android.app.Activity activity) |
private static android.widget.ImageView |
findOverflowMenuButton(android.app.Activity activity,
android.view.ViewGroup viewGroup) |
private static android.view.ViewGroup |
findToolbar(android.view.ViewGroup viewGroup) |
static void |
forceMenuIcons(android.view.Menu menu)
Set the menu to show MenuItem icons in the overflow window.
|
android.view.Menu |
getMenu() |
android.widget.ImageView |
getOverflowMenuButton() |
static android.widget.ImageView |
getOverflowMenuButton(android.app.Activity activity) |
static boolean |
isActionButton(android.view.MenuItem item)
Check if an item is showing (not in the overflow menu).
|
static boolean |
isInOverflow(android.view.MenuItem item)
Check if an item is in the overflow menu.
|
static MenuTintHelper.Builder |
on(android.view.Menu menu) |
void |
reapply()
Sets a ColorFilter and/or alpha on all the
MenuItem s in the
menu, including the OverflowMenuButton. |
void |
setMenuItemIconColor(java.lang.Integer color) |
private static final java.lang.String TAG
private static java.lang.reflect.Method nativeIsActionButton
private final android.view.Menu menu
private final java.lang.Integer originalMenuItemIconColor
private final java.lang.Integer menuItemIconAlpha
private final java.lang.Integer subMenuIconColor
private final java.lang.Integer subMenuIconAlpha
private final java.lang.Integer overflowDrawableId
private final boolean reApplyOnChange
private final boolean forceIcons
private java.lang.Integer menuItemIconColor
private android.widget.ImageView overflowButton
private android.view.ViewGroup actionBarView
private MenuTintHelper(MenuTintHelper.Builder builder)
public static boolean isActionButton(android.view.MenuItem item)
item
- the MenuItem.true
if the MenuItem is visible on the ActionBar.public static boolean isInOverflow(android.view.MenuItem item)
item
- the MenuItemtrue
if the MenuItem is in the overflow menu.isActionButton(MenuItem)
public static void colorMenuItem(android.view.MenuItem menuItem, java.lang.Integer color, java.lang.Integer alpha)
MenuItem
's
icon.menuItem
- The MenuItem
to theme.color
- The color to set for the color filter or null
for
no changes.alpha
- The alpha value (0...255) to set on the icon or null
for no changes.public static void forceMenuIcons(android.view.Menu menu)
menu
- the menu to force icons to showpublic static MenuTintHelper.Builder on(android.view.Menu menu)
public static void colorIcons(android.app.Activity activity, android.view.Menu menu, int color)
activity
- the Activity.menu
- the menu after items have been added.color
- the color for the ColorFilter.public static android.widget.ImageView getOverflowMenuButton(android.app.Activity activity)
activity
- the Activitynull
if it doesn't exist.@Nullable private static android.widget.ImageView findOverflowMenuButton(android.app.Activity activity, android.view.ViewGroup viewGroup)
@Nullable private static android.view.ViewGroup findActionBar(android.app.Activity activity)
@Nullable private static android.view.ViewGroup findToolbar(android.view.ViewGroup viewGroup)
public void apply(android.app.Activity activity)
Sets a ColorFilter and/or alpha on all the MenuItem
s in the
menu, including the OverflowMenuButton.
Call this method after inflating/creating your menu in Activity.onCreateOptionsMenu(Menu)
.
Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.
activity
- the activity to apply the menu tinting on.public void reapply()
Sets a ColorFilter and/or alpha on all the MenuItem
s in the
menu, including the OverflowMenuButton.
This should only be called after calling apply(Activity)
. It is
useful for when MenuItem
s might be re-arranged due to an action
view being collapsed or expanded.
private void colorOverflowMenuItem(android.widget.ImageView overflow)
public android.view.Menu getMenu()
public android.widget.ImageView getOverflowMenuButton()
public void setMenuItemIconColor(java.lang.Integer color)