2

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

2 回答 2

2

这可能不是执行此操作的正确方法,但如果您明确设置 textColor 属性,则可以解决此问题。

<TextView android:id="@+id/text1" 
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content" 
    android:autoLink="all"
    android:textColor="#ffffff"/>

如果我没有提醒您在设置文本颜色时使用样式,那将是我的疏忽,但确实如此。

于 2011-03-29T00:27:20.390 回答
0

在 xml 中的 TextView 上设置它

android:textColor="@android:color/secondary_text_dark_nodisable"

另请参阅此答案

于 2011-06-19T16:04:50.667 回答