改变AlertDialog中超链接的颜色[英] Change color of Hyperlink in AlertDialog

本文是小编为大家收集整理的关于改变AlertDialog中超链接的颜色的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

正常此行为不是戏剧性的,但在三星Galaxy的情况下,默认的AlertDialog背景为蓝色,常规格式化链接(蓝色)消失. 不幸的是,以下代码不会改变链接的颜色.

有人想到一个想法吗?

public void showClickableDialog(String title, String msg) {
    final SpannableString s = new SpannableString(msg);
    Linkify.addLinks(s, Linkify.ALL);

    final AlertDialog d = new AlertDialog.Builder(mContext)
            .setPositiveButton(android.R.string.ok, null).setIcon(
                    R.drawable.logo).setTitle(title).setMessage(s).create();

    d.show();

    // Make the textview clickable. Must be called after show()
    TextView textView = ((TextView) d.findViewById(android.R.id.message));
    // Next Line unfortunately does nothing
    textView.setTextColor(Color.MAGENTA);
    textView.setBackgroundColor(Color.BLACK);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

}

推荐答案

我在我的style.xml中有以下内容,以便制作链接橙色:

<item name="android:textColorLink">#FF9900</item>
所以我假设在代码中你只需要这样做(出于某种原因方法名称与XML属性不一致):

textView.setLinkTextColor(Color.MAGENTA);

本文地址:https://www.itbaoku.cn/post/102460.html

问题描述

Normaly this behavior isn't dramatic but on a Samsung Galaxy S the default AlertDialog background is blue and a normal formatted link (blue) disappears. Unfortunately the below code does not change the color of the link.

Has anyone a idea?

public void showClickableDialog(String title, String msg) {
    final SpannableString s = new SpannableString(msg);
    Linkify.addLinks(s, Linkify.ALL);

    final AlertDialog d = new AlertDialog.Builder(mContext)
            .setPositiveButton(android.R.string.ok, null).setIcon(
                    R.drawable.logo).setTitle(title).setMessage(s).create();

    d.show();

    // Make the textview clickable. Must be called after show()
    TextView textView = ((TextView) d.findViewById(android.R.id.message));
    // Next Line unfortunately does nothing
    textView.setTextColor(Color.MAGENTA);
    textView.setBackgroundColor(Color.BLACK);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

}

推荐答案

I have the following in my style.xml in order to make a link orange:

<item name="android:textColorLink">#FF9900</item>

So I assume in code you just need to do this (for some reason the method name is inconsistent with the XML property):

textView.setLinkTextColor(Color.MAGENTA);