0
我想使用Jetbrains的Anko庫在我的應用程序中輕鬆顯示Android吐司消息。'接收器類型不匹配'與片段和Anko吐司
下面是相關的代碼片段:
val message : CharSequence = "Recycled: ${holder.taskEditText.text}"
(tasksFragment as Fragment).toast(text = message)
和錯誤:
Error:(80, 45) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun Fragment.toast(text: CharSequence): Unit defined in org.jetbrains.anko
public inline fun Fragment.toast(textResource: Int): Unit defined in org.jetbrains.anko
public fun Context.toast(text: CharSequence): Unit defined in org.jetbrains.anko
public fun Context.toast(textResource: Int): Unit defined in org.jetbrains.anko
public inline fun AnkoContext<*>.toast(text: CharSequence): Unit defined in org.jetbrains.anko
public inline fun AnkoContext<*>.toast(textResource: Int): Unit defined in org.jetbrains.anko
我非常新的科特林並一直在尋找一個解決這個問題了一會兒。所有的幫助表示讚賞。
啊。 Anko庫使用'android.app.Fragment'我一直希望使用'android.support.v4.app.Fragment' – sjoshua270
您應該將'anko-support-v4-commons'添加到您的依賴列表中。然後你就可以使用支持片段 –