こんにちは、次のコードを使用して電子メール アドレスと URL をリンクしていますが、必要に応じて機能していますが、URL と電子メール以外の場所をクリックすると、リンクされていない白いテキストが黒くなり、読めなくなります。大したことではありませんが、リンクされていないテキスト onclick の色の書式設定に関するヘルプを煩わせているだけで、大歓迎です。
final SpannableString s = new SpannableString("Some text here before link http://www.google.com some more text then email fake@fake.com");
Linkify.addLinks(s, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
final AlertDialog d = new AlertDialog.Builder(MainMethod.this)
.setPositiveButton(android.R.string.ok, null)
.setIcon(R.drawable.about)
.setTitle(R.string.about_title)
.setMessage( s )
.create();
d.show();
((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
したがって、次のテキスト「リンクの前にいくつかのテキストがあり、次に電子メールが送信されます」は、ダイアログで白く表示されますが、押すと黒くなります
編集:
ジャワ
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.link, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Insert Title Here");
builder.setView(view).create().show();
TextView text=(TextView) findViewById(R.id.link1);
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/link1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Body text with email fake@fake.com and a website http://google.com"
android:autoLink="web|email"
android:textColorLink="#0000ff"
android:textColor="#ffffff"
/>
</LinearLayout>