更改AlertDialog中超链接的颜色

3

通常情况下,这种行为并不会引起太大的影响,但在三星Galaxy S上,默认的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());

}
1个回答

9

我在我的style.xml中添加了以下内容,以使链接变为橙色:

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

我猜在代码中你只需要这样做(由于方法名称与XML属性不一致):

textView.setLinkTextColor(Color.MAGENTA);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接