Linkify properly an email address with subject

半腔热情 提交于 2019-12-23 03:26:19

问题


I want to linkify a email address and put a static subject to the email.

In the layout I have this:

<TextView
    android:id="@+id/textView5"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:autoLink="email"
    android:text="@string/email" />

How can I add the subject to the email? I should do this in the Activity with the addLinks() method, am I right? I tried some combinations but the email was being appended to the subject...

I checked those sources but without luck:

  • Email from a link and Android Intents - bring it home
  • Android Text Links Using Linkify
  • Linkify your Text!

回答1:


I found a solution:

<TextView
     android:id="@+id/textView5"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:gravity="center"
     android:clickable="true"/>

TextView mailTV = (TextView) findViewById(R.id.textView5);
mailTV.setText(Html.fromHtml("<a href=\"mailto:"+getString(R.string.email)+"?subject="+getString(R.string.email_subject)+"\" >"+getString(R.string.email)+"</a>"));
mailTV.setMovementMethod(LinkMovementMethod.getInstance());


来源:https://stackoverflow.com/questions/16316000/linkify-properly-an-email-address-with-subject

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!