![](/img/trans.png)
[英]Xamarin.Android ClassNotFoundException 'mono.android.app.Application'
[英]Converting Kotlin app to Xamarin.Android application
我正在嘗試將 Kotlin (Android) 應用程序轉換為 Xamarin.Android 應用程序。 我遇到了 function 並且無法弄清楚 C# 代碼將是什么。
fun loadDrawable(
activity: Activity,
imageUrl: String?,
@DrawableRes defaultImage: Int,
onLoaded: (image: Drawable) -> Unit) {
val imageToLoad = if (imageUrl.isNullOrEmpty()) defaultImage else imageUrl
Glide.with(activity)
.load(imageToLoad)
.error(defaultImage)
.centerCrop()
.into<CustomTarget<Drawable>>(object : CustomTarget<Drawable>() {
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
onLoaded(resource)
}
override fun onLoadCleared(placeholder: Drawable?) {
placeholder?.let { onLoaded(it) }
}
})
}
在上面的 function 中,我無法將最后一個參數( onLoaded: (image: Drawable) -> Unit )轉換為 function。
這就是我目前在 Kotlin 中調用上述 function 的方式
loadDrawable(requireActivity(), null, R.drawable.bg_default) {
_backgroundManager?.drawable = it
}
如果有人可以幫助我弄清楚如何轉換此代碼(或 C# 中的等效功能),我將不勝感激
謝謝
我能夠使用動作委托實現相同的功能
Action<Drawable> onLoaded
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.