我对Android编程非常陌生,并且已经被带到了帮助完成一个项目。我正在尝试创建一个警报,其中包含指向电话号码的链接以及点击时的地址,将分别启动拨号程序和默认地图应用程序。
目前我的方法是:
Android.App.AlertDialog.Builder builder = new AlertDialog.Builder(activity);
AlertDialog ad = builder.Create();
ad.SetTitle("Quick Info");
var alertMsg = "";
alertMsg += "Address: " + addressString;
alertMsg += "\nPhone Number: " + phoneString;
SpannableString linkedMsg = new SpannableString(alertMsg);
Linkify.AddLinks(linkedMsg, MatchOptions.All);
ad.SetMessage(linkedMsg);
ad.SetButton("OK", (s, er) => { });
ad.Show();
似乎工作,因为它将电话号码和地址识别为链接(突出显示并加下划线),但当我尝试点击它们时,没有任何反应。我觉得我错过了一个简单的财产,或者说我可以点击,但我似乎无法找到任何东西!
答案 0 :(得分:1)
非常简单:
Android.App.AlertDialog.Builder builder = newAlertDialog.Builder(activity);
AlertDialog ad = builder.Create();
ad.SetTitle("Quick Info");
var alertMsg = "";
alertMsg += "Address: " + addressString;
alertMsg += "\nPhone Number: " + phoneString;
SpannableString linkedMsg = new SpannableString(alertMsg);
Linkify.AddLinks(linkedMsg, MatchOptions.All);
ad.SetMessage(linkedMsg);
ad.SetButton("OK", (s, er) => { });
ad.Show();
// major key
((TextView)ad.FindViewById(Android.Resource.Id.Message)).MovementMethod = LinkMovementMethod.Instance;