追加のサポートが必要な場合に備えて、メールでお問い合わせください。メールアドレスはこちらです。
しかし、私は彼らが電子メールのリンクをクリックして、電子メール クライアントを開くことができるようにしたいと考えています。それは可能ですか?それとも悪い習慣ですか?
それが合理的な慣行である場合、どのように行うことができますか?
追加のサポートが必要な場合に備えて、メールでお問い合わせください。メールアドレスはこちらです。
しかし、私は彼らが電子メールのリンクをクリックして、電子メール クライアントを開くことができるようにしたいと考えています。それは可能ですか?それとも悪い習慣ですか?
それが合理的な慣行である場合、どのように行うことができますか?
でインテントを起動する必要がありますonClickListener
。
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain"); // send email as plain text
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some@email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
受け入れられた回答は電子メールで機能する可能性がありますが、電子メール、連絡先番号、Web リンクなどのさまざまなパターンを検出し、これらのパターンに対して個別のクリック実装を設定する場合は、CustomClickableEmailPhoneTextviewを使用することをお勧めします
ライブラリを使用するためのサンプルコード。
CustomPartialyClickableTextview customPartialyClickableTextview= (CustomPartialyClickableTextview) findViewById(R.id.textViewCustom);
/**
* Create Objects For Click Patterns
*/
ClickPattern email=new ClickPattern();
ClickPattern phone=new ClickPattern();
ClickPattern weblink=new ClickPattern();
/**
* set Functionality for what will happen on click of that pattern
* In this example pattern is email
*/
email.setOnClickListener(new ClickPattern.OnClickListener() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this,"email clicked",Toast.LENGTH_LONG).show();
}
});
/**
* set Functionality for what will happen on click of that pattern
* In this example pattern is phone
*/
phone.setOnClickListener(new ClickPattern.OnClickListener() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this,"phone clicked",Toast.LENGTH_LONG).show();
}
});
/**
* set Functionality for what will happen on click of that pattern
* In this example pattern is weblink
*/
weblink.setOnClickListener(new ClickPattern.OnClickListener() {
@Override
public void onClick() {
Toast.makeText(MainActivity.this,"website clicked",Toast.LENGTH_LONG).show();
}
});
/**
* set respective regex string to be used to identify patter
*/
email.setRegex("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b"); // regex for email
phone.setRegex("[1-9][0-9]{9,14}"); // regex for phone number
weblink.setRegex("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); // regex for weblink
/**
* add click pattern to the custom textview - first parameter is tag for reference second parameter is ClickPattern object
*/
customPartialyClickableTextview.addClickPattern("email",email);
customPartialyClickableTextview.addClickPattern("phone",phone);
customPartialyClickableTextview.addClickPattern("weblink",weblink);