问题描述
正常此行为不是戏剧性的,但在三星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);
问题描述
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);