'Menu item with action layout: how to modify icon color programmatically

I use this menu:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/menu_notifications"
        android:orderInCategory="1"
        app:actionLayout="@layout/notification_toolbar"        
        android:visible="false"
        app:showAsAction="always" />

</menu>

Then here you are my action layout:

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_gravity="center"
    android:clickable="true"
    style="@android:style/Widget.ActionButton">

    <com.app.ui.widget.IconView == ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:src="@drawable/ic_notifications_tb"
        android:id="@+id/icon"/>

    <FrameLayout
        android:id="@+id/count_layout"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:layout_marginLeft="11dp"
        android:background="@drawable/circle_red"
        android:visibility="gone"/>

</RelativeLayout>

And I want to update the color of "icon" programmatically. I tried to parse my toolbar but it doesn't work.

Thank you very much guys!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source