setIcon funcgion does not work on MaterialButton, setCompoundDrawableWithIntrinsicBounds does

12 Views Asked by At

I am on material version "1.9.0".

I have a UI that use different presentations of a material button. When the icon is set in xml it works & is visible. However when I try to set the same icon using the setIcon & iconTint functions it doesn't work. I can get the desired behaviour to work using setCompoundDrawableWithIntrinsicBounds but I would prefer to use the original method that is used in the xml. Here is my code. (xbutton is a MaterialButton

        xbutton.icon.setVisible(true, true)
        xbutton.icon = ResourcesCompat.getDrawable(resources, R.drawable.ic_info, null)
        xbutton.iconTint = ResourcesCompat.getColorStateList(resources, R.color.orange, null)
        Handler(Looper.getMainLooper()).post {
            binding.cardview.forceLayout()
        }

I don't see the space in the button for the icon so the icon isn't there; it isn't an issue where the icon is transparent

0

There are 0 best solutions below