【问题标题】:how to change stroke color in android by kotlin code?如何通过 kotlin 代码更改 android 中的笔触颜色?
【发布时间】:2019-02-13 09:01:40
【问题描述】:

我想在 kotlin 中手动更改 imageview 的边框颜色。

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

我试过了,但它不起作用。

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    你需要使用setStroke方法来改变imageview的边框颜色。

    backgroundGradient.setStroke(1, ContextCompat.getColor(context, someColorId))
    

    【讨论】:

    【解决方案2】:

    你可以用这个方法

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

    还有其他可用的选项可以传递给方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 2020-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多