kotlin change materialbutton icon color programmatically
To change the MaterialButton icon color programmatically in Kotlin, you can follow these steps:
- Get a reference to the MaterialButton:
val materialButton = findViewById<MaterialButton>(R.id.materialButton)
Replace R.id.materialButton
with the actual ID of your MaterialButton.
- 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.
- 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.