当我点击Android中的电子邮件时,主题始终为空

时间:2017-01-18 11:03:25

标签: android xamarin textview mailto autolink

我正在开发一款应用,我添加了一个简单的 TextView ,其中包含 autoLink =" email"

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:textSize="16dp"
    android:autoLink="email"
    android:text="@string/lblContactUs" />

我的字符串如下所示:

<string name="lblContactUs">Federico Navarrete <a href="mailto:fanm_45@outlook.com?Subject=Contact%20Us%TipSal" target="_top">fanm_45@outlook.com</a></string>

总是,当我点击链接时,主题是空的。

Empty subject

另外,我注意到如果我在标签内没有真正的电子邮件:

<a href="mailto:fanm_45@outlook.com?Subject=Contact%20Us%TipSal">fanm_45@outlook.com</a>

但是,我有这样的事情:

<a href="mailto:fanm_45@outlook.com?Subject=Contact%20Us%TipSal">Contact us</a>

链接没有做任何事情,代码完全被忽略。有谁知道我应该改变什么?或者为什么不工作?

PS: 我已经在Gmail和Blue Mail客户端上测试过,我得到了相同的结果。

1 个答案:

答案 0 :(得分:2)

我认为textview无法识别此<a href="mailto:"/>。但textView可以识别邮件地址。

您可以将string.xml更改为

<string name="lblContactUs">fanm_45@outlook.com</string>

行为应与

相同

<string name="lblContactUs"><a href="mailto:">fanm_45@outlook.com</a></string>

为了达到您的要求,您应该使用客户范围进行邮件发送。

<强> 1。您可以通过ClickableSpan

点击设置文字
class MyURLSpan : ClickableSpan
{
    MainActivity mActivity;

    public MyURLSpan(MainActivity activity)
    {
        mActivity = activity;
    }
    public override void OnClick(View widget)
    {
        Intent email = new Intent(Intent.ActionSend);
        email.SetType("text/plain"); 
        //real device please use  email.SetType("message/rfc822");
        email.PutExtra(Intent.ExtraEmail, "mikexxma@outlook.com");  
        email.PutExtra(Intent.ExtraSubject, "hello");    
        email.PutExtra(Intent.ExtraText, "hello mike ma");
        mActivity.StartActivity(email);
    }
}

<强> 2。将点击监听器添加到文本中:

private SpannableString getClickableSpan()
{
    string s = "contact me";
    SpannableString sp = new SpannableString(s);
    sp.SetSpan(new MyURLSpan(this), 0, s.Length, SpanTypes.InclusiveInclusive);
    return sp;
}

第3。将范围设置为textview

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    // Set our view from the "main" layout resource
     SetContentView (Resource.Layout.Main);
    mailTV = (TextView)FindViewById(Resource.Id.textView2);
    mailTV.SetText(getClickableSpan(), TextView.BufferType.Spannable);         
    mailTV.MovementMethod = LinkMovementMethod.Instance;
}

你可以找到:

enter image description here