您好,我正在使用以下代码来链接电子邮件地址和网址,这就像我需要的那样工作,但是如果您单击网址和电子邮件之外的任何位置,未链接的白色文本将变为黑色且不可读。没什么大不了的,但只是令人讨厌的任何帮助格式化未链接文本的颜色 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>