【问题标题】:Subject is always empty when I do click on an email in Android当我在 Android 中单击电子邮件时,主题始终为空
【发布时间】:2017-01-18 11:03:24
【问题描述】:

我正在开发一个应用程序,并添加了一个简单的 TextViewautoLink="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>

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

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

<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 客户端上进行了测试,得到了相同的结果。

【问题讨论】:

标签: android xamarin textview mailto autolink


【解决方案1】:

我认为 textview 无法识别这个&lt;a href="mailto:"/&gt;。但是textView可以识别邮件地址。

您可以将您的 string.xml 更改为

&lt;string name="lblContactUs"&gt;fanm_45@outlook.com&lt;/string&gt;

行为应该与

相同

&lt;string name="lblContactUs"&gt;&lt;a href="mailto:"&gt;fanm_45@outlook.com&lt;/a&gt;&lt;/string&gt;

为了满足您的要求,您应该使用客户跨度进行邮件发送。

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;
}

你可以找到:

【讨论】:

  • 感谢您的回答非常棒:D.
猜你喜欢
  • 2017-05-26
  • 1970-01-01
  • 2017-01-03
  • 2018-10-08
  • 1970-01-01
  • 2013-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多