警报对话框 Linkify 但保持文本白色

发布于 2024-10-27 09:43:04 字数 2067 浏览 0 评论 0原文

您好,我正在使用以下代码来链接电子邮件地址和网址,这正如我需要的那样工作,但是如果您单击网址和电子邮件之外的任何位置,未链接的白色文本就会变成黑色且不可读。没什么大不了的,但只是令人烦恼的任何关于格式化未链接文本 onclick 的颜色的帮助将不胜感激。

            final SpannableString s = new SpannableString("Some text here before link http://www.google.com some more text then email [email protected]");
        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());

因此,现在以下文本“在链接更多文本和电子邮件之前,此处有一些文本”在对话框中显示白色,但在按下时变为黑色

编辑:

Java

       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 [email protected] and a website http://google.com"
   android:autoLink="web|email"
   android:textColorLink="#0000ff"
   android:textColor="#ffffff"
  />

</LinearLayout>

Hello I am using the following code to linkify email addresses and urls and that is working just as i need it to however if you click any where besides the urls and emails the white text that is unlinked becomes black and unreadable. Not a huge deal but just something that's annoying any help on formatting the color of the unlinked text onclick would be greatly appreciated.

            final SpannableString s = new SpannableString("Some text here before link http://www.google.com some more text then email [email protected]");
        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());

So now the following text "Some text here before link some more text then email" shows white in the dialog but turns black when pressed

EDIT:

Java

       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 [email protected] and a website http://google.com"
   android:autoLink="web|email"
   android:textColorLink="#0000ff"
   android:textColor="#ffffff"
  />

</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以可爱出名 2024-11-03 09:43:04

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

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

如果我没有提醒您使用 样式<,那我就失职了/a> 设置文本颜色时,但它就在那里。

This is probably not the correct way to do this, but if you explicitly set the textColor attribute, you can get around this issue.

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

I would be remiss if I didn't remind you to use styles when setting your text color, but there it is.

叹梦 2024-11-03 09:43:04

在 xml 中的 TextView 上设置此选项

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

另请参阅此答案

Set this on your TextView in xml

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

See also this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文