警报对话框 Linkify 但保持文本白色
您好,我正在使用以下代码来链接电子邮件地址和网址,这正如我需要的那样工作,但是如果您单击网址和电子邮件之外的任何位置,未链接的白色文本就会变成黑色且不可读。没什么大不了的,但只是令人烦恼的任何关于格式化未链接文本 onclick 的颜色的帮助将不胜感激。
final SpannableString s = new SpannableString("Some text here before link http://www.google.com some more text then email [email protected]");
Linkify.addLinks(s, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
final AlertDialog d = new AlertDialog.Builder(MainMethod.this)
.setPositiveButton(android.R.string.ok, null)
.setIcon(R.drawable.about)
.setTitle(R.string.about_title)
.setMessage( s )
.create();
d.show();
((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
因此,现在以下文本“在链接更多文本和电子邮件之前,此处有一些文本”在对话框中显示白色,但在按下时变为黑色
编辑:
Java
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.link, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Insert Title Here");
builder.setView(view).create().show();
TextView text=(TextView) findViewById(R.id.link1);
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/link1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Body text with email [email protected] and a website http://google.com"
android:autoLink="web|email"
android:textColorLink="#0000ff"
android:textColor="#ffffff"
/>
</LinearLayout>
Hello I am using the following code to linkify email addresses and urls and that is working just as i need it to however if you click any where besides the urls and emails the white text that is unlinked becomes black and unreadable. Not a huge deal but just something that's annoying any help on formatting the color of the unlinked text onclick would be greatly appreciated.
final SpannableString s = new SpannableString("Some text here before link http://www.google.com some more text then email [email protected]");
Linkify.addLinks(s, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
final AlertDialog d = new AlertDialog.Builder(MainMethod.this)
.setPositiveButton(android.R.string.ok, null)
.setIcon(R.drawable.about)
.setTitle(R.string.about_title)
.setMessage( s )
.create();
d.show();
((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
So now the following text "Some text here before link some more text then email" shows white in the dialog but turns black when pressed
EDIT:
Java
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.link, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Insert Title Here");
builder.setView(view).create().show();
TextView text=(TextView) findViewById(R.id.link1);
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/link1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Body text with email [email protected] and a website http://google.com"
android:autoLink="web|email"
android:textColorLink="#0000ff"
android:textColor="#ffffff"
/>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能不是执行此操作的正确方法,但如果您显式设置 textColor 属性,则可以解决此问题。
如果我没有提醒您使用 样式<,那我就失职了/a> 设置文本颜色时,但它就在那里。
This is probably not the correct way to do this, but if you explicitly set the textColor attribute, you can get around this issue.
I would be remiss if I didn't remind you to use styles when setting your text color, but there it is.
在 xml 中的 TextView 上设置此选项
另请参阅此答案。
Set this on your TextView in xml
See also this answer.