I need to change the icon tint of my MaterialButton, the icon is a an xml vector asset and I can change the tint easily in the xml layout, but I need to change the color programmatically in a click, I can't be able to find something related of this issue, This is my button:
<com.google.android.material.button.MaterialButton
android:id="@+id/btnShowDepartmentList"
style="@style/com.madison.Button.IconButton"
app:iconSize="32dp"
android:padding="0dp"
android:paddingLeft="5dp"
android:paddingStart="5dp"
app:icon="@drawable/ic_list_thumbnails"
android:layout_width="42dp"
android:layout_height="42dp"
app:iconTint="@color/orangeLighter"
tools:ignore="RtlSymmetry"/> ```
To change icon color of Floating Action Button in Kotlin Android we have to set the tint attribute (in layout file) or imageTintList parameter (in Kotlin program) of FAB with the required color.
You will want to use the setIconTint(ColorStateList)
or setIconTintResource(Int)
methods of MaterialButton. For example:
val button = findViewById<MaterialButton>(R.id.btnShowDepartmentList)
button.setOnClickListener {
button.setIconTintResource(R.color.orangeLighter)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With