Error:(63, 13) Unresolved reference: textInputLayout
Error:(64, 17) Unresolved reference: textInputEditText
尝试在 kotlin anko 中添加 textInputLayout 和 textInputEditText 时出现上述错误消息。
以下是我的代码 -
private fun test(context: Context): View{
return with(context){
verticalLayout {
textInputLayout {
textInputEditText{}
}
}
}
}
最佳答案
在您希望的任何位置创建一个 kotlin 代码文件。在没有任何类声明的情况下放置下面的代码。
inline fun ViewManager.textInputEditText() = textInputEditText {}
inline fun ViewManager.textInputEditText(theme: Int = 0, init: TextInputEditText.() -> Unit) = ankoView({ TextInputEditText(it) }, theme, init)
inline fun ViewManager.textInputLayout() = textInputLayout {}
inline fun ViewManager.textInputLayout(theme: Int = 0, init: TextInputLayout.() -> Unit) = ankoView({ TextInputLayout(it) }, theme, init)
希望对你有帮助
编辑:根据@A Boschman 的评论,anko 非常新,几乎没有文档。当我遇到同样的问题时,我在互联网上搜索了很多但没有找到任何文档。
我的解决方案基于下面提到的 GitHub 上的线程——(也没有理论解释)
https://github.com/Kotlin/anko/issues/205
https://github.com/Kotlin/anko/issues/264
关于android - 如何在 Kotlin anko 中使用 TextInputLayout & TextInputEditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45006104/