-1

Is there a way of only changing the left drawable in kotlin using code? In my case I have a speedmode selector from 1 to 8 and when a car(s) is selected you then press a speedmode and the icon changes in the button of the car. I have this but it removes the right drawable.

 for (speedModeSelecter in speedList)
    {
        speedModeSelecter.setOnClickListener{
            for(kartBox in kartList)
            {
                if(kartBox.isChecked) {
                   kartBox.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_speedmode1, 0 ,0 ,0)
                }
            }
        }
    }

a picture of what it should look like here

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
mohammed_sajid
  • 233
  • 2
  • 18

1 Answers1

0

For Kotlin

var leftDrawable: Drawable =
    getContext()
        .getResources()
        .getDrawable(R.drawable.yourdrawable)

var drawables: Array<Drawable> = button.compoundDrawables

//setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
button.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, drawables[1], drawables[2], drawables[3])