我想在必填字段中设置符号*。为此,我可以使用以下代码行:
所有的代码都很好,但是在下面这行出现了错误:
那么我该如何解决这个错误呢?
我要在必填字段中设置*号。为此,我可以使用以下代码行:
hint_mobile!!.setText(Html.fromHtml(resources.getString(R.string.mobile_number) + "<sup> * </sup>"));
这段代码是有效的,但我无法将星号*设置为红色。
所以我使用了另一个示例,如下:
hint_mobile!!.setText(resources.getString(R.string.mobile_number))
val str = hint_mobile!!.text.toString()
val loc = hint_mobile!!.text.toString().indexOf("*")
str!!.setSpan(ForegroundColorSpan(Color.RED), loc, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
所有的代码都很好,但是在下面这行出现了错误:
str!!.setSpan(ForegroundColorSpan(Color.RED), loc, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
错误
Unresolved reference: setSpan
那么我该如何解决这个错误呢?
str
是一个字符串。String
类没有setSpan
方法。您可以通过在正确的对象上调用setSpan
来解决此错误。 - yole