【发布时间】:2019-02-13 09:01:40
【问题描述】:
我想在 kotlin 中手动更改 imageview 的边框颜色。
val backgroundGradient = imgIcon.getBackground() as GradientDrawable
backgroundGradient.setColor(getResources().getColor(R.color.yellow))
我试过了,但它不起作用。
【问题讨论】:
我想在 kotlin 中手动更改 imageview 的边框颜色。
val backgroundGradient = imgIcon.getBackground() as GradientDrawable
backgroundGradient.setColor(getResources().getColor(R.color.yellow))
我试过了,但它不起作用。
【问题讨论】:
你需要使用setStroke方法来改变imageview的边框颜色。
backgroundGradient.setStroke(1, ContextCompat.getColor(context, someColorId))
【讨论】:
你可以用这个方法
backgroundGradient.setStroke(width : Int, color : Int)
还有其他可用的选项可以传递给方法
【讨论】: