1

i want to change border color for imageview manually in kotlin.

val backgroundGradient = imgIcon.getBackground() as GradientDrawable
backgroundGradient.setColor(getResources().getColor(R.color.yellow))

i tried this but it's not working.

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50

2 Answers2

2

you can use this method

backgroundGradient.setStroke(width : Int, color : Int)

there are other options available you can pass to method

Vishal
  • 551
  • 3
  • 11
2

You need to use setStroke method to change border color of imageview.

backgroundGradient.setStroke(1, ContextCompat.getColor(context, someColorId))
Nikunj
  • 3,937
  • 19
  • 33