kotlin change materialbutton icon color programmatically

To change the MaterialButton icon color programmatically in Kotlin, you can follow these steps:

  1. Get a reference to the MaterialButton:
val materialButton = findViewById<MaterialButton>(R.id.materialButton)

Replace R.id.materialButton with the actual ID of your MaterialButton.

  1. Create a ColorStateList object with the desired color:
val colorStateList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.iconColor))

Replace R.color.iconColor with the resource ID of the desired color.

  1. Set the color of the icon using the setIconTint method:
materialButton.iconTint = colorStateList

That's it! The icon color of the MaterialButton will now be changed programmatically.