Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView to send email when clicked

Tags:

android

I have a TextView with android:autoLink="email".

If I put my email address in there then a link appears that I can click.

How do I have different text appear (for example 'Send Feedback') instead of the email address but still behave the same when clicked?

Thanks

like image 776
neildeadman Avatar asked Jan 13 '11 17:01

neildeadman


2 Answers

To achieve what I wanted required a different approach:

TextView feedback = (TextView) findViewById(R.id.TextViewSendFeedback); feedback.setText(Html.fromHtml("<a href=\"mailto:[email protected]\">Send Feedback</a>")); feedback.setMovementMethod(LinkMovementMethod.getInstance()); 

This basically places HTML in the TextView so I get a link saying 'Send Feedback' but clicking it opens the default email application.

Word of warning: Trying this in the emulator didn't initially work for me, saying it was unsupported. This was just because I didn't have an email account setup. Setting one up in the emulator made the link work as I wanted.

like image 56
neildeadman Avatar answered Sep 21 '22 02:09

neildeadman


You can use both links and email if you set the following param in the TextView

android:autoLink="web|email" 

the links will be opened in the browser and the mails will be sent by the default mail client

like image 44
Hakem Zaied Avatar answered Sep 21 '22 02:09

Hakem Zaied