我正在使用 Xamarin 并试图让自动链接为 TextView 工作。
这是我的代码:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace TestTextViewAutoLink
{
[Activity (Label = "TestTextViewAutoLink", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
TextView textView = new TextView (this.ApplicationContext);
textView.AutoLinkMask = Android.Text.Util.MatchOptions.PhoneNumbers;
textView.Text = "This is a phone number 0800 32 32 32";
SetContentView(textView);
}
}
}
正在显示文本,但是当我单击文本时出现以下错误:
不幸的是,TestTextViewAutoLink 已停止
我可以帮忙吗?
提前致谢。
编辑
我也试过这段代码,但是发生了同样的错误:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
TextView textView = new TextView (this.ApplicationContext);
//textView.AutoLinkMask = Android.Text.Util.MatchOptions.PhoneNumbers;
textView.Text = "This is a phone number 0800 32 32 32";
Linkify.AddLinks(textView, MatchOptions.PhoneNumbers);
SetContentView(textView);
}