我正在使用渲染器列出文本链接,当我点击它时会打开浏览器。我希望当我单击链接时它指示单击的链接并返回变量中的值。渲染器中的哪个事件可以在触发时检查?
public class CustomLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
SetHtmlText();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
SetHtmlText();
}
private void SetHtmlText()
{
if (Control != null)
{
Control.SetText(GetSpannedHtml(), TextView.BufferType.Spannable);
Control.MovementMethod = LinkMovementMethod.Instance; // Makes links clickable
}
}
private ISpanned GetSpannedHtml()
{
var source = Element?.Text ?? "";
var html = Build.VERSION.SdkInt >= BuildVersionCodes.N
? Html.FromHtml(source, FromHtmlOptions.ModeLegacy)
: Html.FromHtml(source);
return html;
}
}