1

我正在写一个简单的小册子应用程序。我在包含电子邮件地址的文本视图中有文本。

<string name="wbl_contacts">
<p><strong>CONTACT</strong></p>
<p>
  <strong>Where you can find us</strong>
  1525 Newton St NW
  Washington D.C., DC 20010
202.667.1192
  For current listing of class schedule at each of our sites, e-mail <a href="mailto:enroll@wblinc.org.">enroll@wblinc.org</a>
  To learn about volunteer opportunities e-mail <a href="mailto:volunteer@wblinc.org">volunteer@wblinc.org</a>
  To submit your resume for internship consideration e-mail <a href="mailto:intern@wblinc.org">intern@wblinc.org</a>
  To submit work for consideration for publication in the WBL journal email <a href="mailto:submissions@wblinc.org">submissions@wblinc.org</a>
  All other questions can be directed to <a href="mailto:info@wblinc.org">info@wblinc.org</a>
or call us at 202-667-1192 </p>
    </string>

我正在尝试使用 Intent 类来增加邮件应用程序,如下所示:

//setting textviews
        tv1 = (TextView)findViewById(R.id.tv1);
        tv1.setMovementMethod(LinkMovementMethod.getInstance());
        //tv1.setText(Html.fromHtml(getString(R.string.wbl_contacts)));

        tv1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                //This will open an email client.  Find a way to use this code
                //to open all email address on any android app page
                Intent emailintent = new Intent(android.content.Intent.ACTION_SEND);
                emailintent.setType("text/html");
                emailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {tv1.getText().toString()});
                emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
                emailintent.putExtra(android.content.Intent.EXTRA_TEXT,"");
                startActivity(Intent.createChooser(emailintent, "Send mail..."));
            }
            });

当我运行我的应用程序时,似乎整个 TextView 都是可点击的,即使电子邮件链接都被高亮显示,好像它们是可链接的......有点丢失。

任何建议或帮助将不胜感激。

4

1 回答 1

0

是的,您不应该将 Intent 用于这种行为。相反,您应该链接您的 TextView。您可以在此处阅读有关 linkify的更多信息。

您将执行以下操作:

Linkify.addLinks(tv1 , Linkify.ALL);

或者,如果您只有电子邮件地址而没有 href:

Linkify.addLinks(tv1 , Linkify.EMAIL_ADDRESSES);

编辑额外答案

您使用 HTML 语法而不是带有电子邮件的常规文本,所以也许您应该使用:

tv1.setText(Html.fromHtml("your string");

并非所有 HTML 标签都受 Android 支持,但可以在此处找到支持的 HTML 标签列表。

于 2013-07-17T04:19:56.477 回答