Why does Kotlin not allow me to apply a color filter to the overflow icon in my Toolbar?
Expression 'colorFilter' of type 'ColorFilter' cannot be invoked as a function. The function 'invoke()' is not found
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:minHeight="?android:attr/actionBarSize"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:id="@+id/toolbar_textLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginStart="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Material.Widget.ActionBar.Title"/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
Kotlin
mToolbar.overflowIcon?.colorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP)
//
val myAttr = intArrayOf(R.attr.tintColor)
val taAttr = this.theme.obtainStyledAttributes(myAttr)
val colorAttr = taAttr.getColor(0, Color.BLACK)

TL;DR: Change
colorFilter()tosetColorFilter().There are two
setColorFilter()methods onDrawable.One takes a
ColorFilter. That matches a correspondinggetColorFilter()method. Kotlin treats those as being syntactically equal to avarnamedcolorFilter. So, if you had aColorFilterobject, you could write:The other
setColorFilter()call takes the two parameters that you are specifying: the color and thePorterDuff.Mode. However, that method issetColorFilter(), notcolorFilter(). So, either switch tosetColorFilter()or:Since you are trying to reference
colorFilter, Kotlin assumes that you mean thecolorFilterproperty, and that is not a function type and cannot be called like one.