widget has an unresolved type,and thus it was upcasted to android.view.View

使用 KotlinView Binding 来绑定 View, 对于框架提供的控件没有任何问题,但是对自定义控件会出现如下错误:

比如,有自定义控件 com.example.customText

xx.xml

1
2
3
4
<com.example.customText
adnroid:id='@+id/custom_text'
...
/>

如果直接使用

1
custom_text.text = 'Hello'

会有如下错误

1
widget has an unresolved type 'com.example.customText',and thus it was upcasted to 'android.view.View'

需要先做类型转换:

1
2
val customtext as customText
customtext.text = 'Hello'