Android Menu Icon Tint (Kotlin)

May 10, 2018
Change MenuItem icon color

By XML

Use app:iconTint.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_share"
        android:title="Share"
        android:icon="@drawable/ic_share_black_24dp"
        app:iconTint="@android:color/white"
        app:showAsAction="ifRoom" />
</menu>        

NOTE: If you use android:iconTint, it will complaint of Attribute iconTint is only used in API level 26 and higher.

By Code

override fun onCreateOptionsMenu(menu: Menu): Boolean {    menuInflater.inflate(R.menu.menu_test, menu)    // val menu = menu.findItem(R.id.action_layout)    for (i in 0 until menu.size()) {        var menuItem = menu.getItem(i)        val icon = menuItem.icon        if (icon != null) {          DrawableCompat.setTint(icon, ContextCompat.getColor(this, android.R.color.white))        }    }    // return true    return super.onCreateOptionsMenu(menu)}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.