【问题标题】:Change color of Hyperlink in AlertDialog在 AlertDialog 中更改超链接的颜色
【发布时间】:2010-12-27 22:16:18
【问题描述】:

通常这种行为并不引人注目,但在三星 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());

}

【问题讨论】:

    标签: android


    【解决方案1】:

    我的style.xml 中有以下内容以使链接变为橙色:

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

    所以我假设在代码中你只需要这样做(由于某种原因method 名称与 XML 属性不一致):

    textView.setLinkTextColor(Color.MAGENTA);
    

    【讨论】:

      猜你喜欢
      • 2016-06-28
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 2016-01-01
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多