【发布时间】:2018-01-29 07:35:49
【问题描述】:
我已经为一个将 HTML 代码呈现为文本的标签制作了一个自定义渲染器。
当我尝试设置格式化文本时出现此错误:
未处理的异常: Java.Lang.NoSuchMethodError:没有静态方法“Landroid/text/Html;.fromHtml(Ljava/lang/String;I)Landroid/text/Spanned;”发生
这是我的一段代码:
Control.SetText(Html.FromHtml(View.Text.ToString(), FromHtmlOptions.ModeLegacy), TextView.BufferType.Spannable);
这仅在 Android 6.0 上发生,从 7.0 开始一切正常。
我该如何解决这个问题?
有解决方法吗?
谢谢!
更新
感谢@Jon Douglas,我以这种方式解决了问题:
if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.N) {
Control.SetText(Html.FromHtml(View.Text.ToString(), FromHtmlOptions.ModeLegacy), TextView.BufferType.Spannable);
} else {
// For API < 24
Control.SetText(Html.FromHtml(View.Text.ToString()), TextView.BufferType.Normal);
}
对于“else”路径,VisualStudio 告诉我它已被弃用,但它仍然可以编译。
【问题讨论】:
标签: c# android xamarin xamarin.forms nosuchmethoderror