【发布时间】:2022-01-10 21:00:24
【问题描述】:
我在 Android Studio 中使用 Material 概述按钮(材料版本为 1.4.0)。 我想在按下按钮时更改轮廓颜色。所以,
binding.activeButton.setOnClickListener{
binding.activeButton.setStrokeColor(Color.parseColor("#FFFFFF"))
}
但是,我不能使用setStrokeColor 方法。
它说“未解决的参考:setStrokeColor”
我仍然可以在 XML 文件中使用app:strokeColor="@color/white",但我不能在活动文件中使用setStrokeColor 方法。
会是什么原因?是材料设计版本的原因吗?
【问题讨论】:
-
这些是因为koltin版本的一些错误,尝试更新kotlin版本。有时这些错误也存在,但项目运行。你可以试试看。同样在 kotlin 中,我们真的不需要使用 getter/setter 方法。我检查了你的代码,它需要 colorStateList。 ** binding.activeButton.strokeColor = ContextCompat.getColorStateList(requireContext(),R.color.colorPrimary)**
标签: android kotlin material-design