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

查看:118
本文介绍了在AlertDialog更改超链接的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Normaly这种行为并没有什么特别之处,但在三星Galaxy S默认AlertDialog背景为蓝色和正常格式化链接(蓝)消失。 不幸的是,跌破code不改变链接的颜色。

有没有人一个想法?

 公共无效showClickableDialog(标题字符串,字符串味精){
    最后SpannableString S =新SpannableString(MSG);
    Linkify.addLinks(S,Linkify.ALL);

    最后AlertDialog D =新AlertDialog.Builder(mContext)
            .setPositiveButton(android.R.string.ok,空).setIcon(
                    R.drawable.logo).setTitle(标题).setMessage(S).create();

    d.show();

    //使TextView的点击。演出后,必须调用()
    TextView中的TextView =((TextView中)d.findViewById(android.R.id.message));
    //下一行遗憾的是并没有什么
    textView.setTextColor(Color.MAGENTA);
    textView.setBackgroundColor(Color.BLACK);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

}
 

解决方案

我有以下我的 style.xml 为了使一个链接橙色:

 <项目名称=机器人:textColorLink>#FF9900< /项目>
 

所以,我认为在code,你只需要做到这一点(由于某种原因,<一个href="http://developer.android.com/reference/android/widget/TextView.html#setLinkTextColor%28int%29">method名字是不符合XML属性):

  textView.setLinkTextColor(Color.MAGENTA);
 

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);

这篇关于在AlertDialog更改超链接的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆