问题
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