How to set Toolbars NavIcon ripple color programmatically?

1.4k views Asked by At

The color of an Activity needs to become changed during runtime. Setting the color of the ToolBar and StatusBar, text colors, etc. programmatically works fine.

Also altering the color of the NavIcon works fine.

    final Drawable immutableNavIcon = toolbar.getNavigationIcon();
    if (immutableNavIcon != null) {
        Drawable navIcon = immutableNavIcon.mutate();
        navIcon.setColorFilter(foregroundColor, PorterDuff.Mode.SRC_ATOP);
        toolbar.setNavigationIcon(navIcon);
    }

How to change also the ripple color of the NavIcon?

1

There are 1 answers

1
Sjd On

Use this theme in your toolbar..

<style name="ToolbarTheme"
  parent="Widget.AppCompat.Toolbar">
<item name="actionMenuTextColor">#1bff3a</item>
<item name="colorControlNormal">#FFF</item>
<item name="colorControlActivated">#FFF</item>
<item name="android:textColorPrimary">#FFF</item>
<item name="actionButtonStyle">@style/Widget.AppCompat.ActionButton</item>
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="selectableItemBackgroundBorderless">?android:selectableItemBackground</item>
<item name="colorControlHighlight">@color/accentColor</item>

see here background ripple effect