Android的Linkify链接文字颜色忽略,CSS样式将覆盖可能吗? [英] Android Linkify links textColor ignored, css style overrides possible?
问题描述
我在我的应用程序中使用 Linkify
,并访问过的链接文字显示为暗紫色。我的总体布局的背景颜色是深蓝色的,所以这是不可能的阅读。文本设置为白色,但是访问过的链接都显示为暗紫色。我如何重写呢?
< TextView的Android版本:文本=网站:
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =14dip
机器人:paddingBottom会=2DIP
机器人:后台=#FFFFFF
机器人:文字颜色=#577dbe/>
< TextView的Android版本:文本=http://www.mysite.com/
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =12dip
机器人:paddingBottom会=6dip
机器人:文字颜色=#FFFFFF
机器人:ID =@ + ID / contactWeb1/>
这竟然是一个简单的解决方案!
然而,你将不能够做到访问
/ 没有访问
分化。
TextView的contactWeb1 =(TextView中)findViewById(R.id.contactWeb1);
noteView.setText(http://www.blablaasd.com/);
noteView.setLinkTextColor(Color.red); //例如
Linkify.addLinks(noteView,Linkify.ALL);
我的试图赶上参观了国家
使用
noteView.setLinkTextColor(getResources()getColorStateList(R.color.colors)。);
相反
的
noteView.setLinkTextColor(Color.red);
在 RES /
创建文件夹颜色
创造 colors.xml
在 RES /彩色/
colors.xml
< XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目
机器人:state_window_focused =真正的机器人:颜色=#00FF00>
< /项目>
<项目
机器人:state_window_focused =真正的机器人:颜色=#00FF00>
< /项目>
<项目的android:颜色=#FF00FF/>
< /选择器>
我已经尽了最大努力赶上访问状态。我尝试了所有的状态的选择可以采取。
我可能会错过如果你发现,分享(:
替代的解决方案(仅适用于HTML链接的作品)
设置字体颜色编程的
缺点的(要当心了这一点)
-
您必须抓住它是否被访问过,或没有(这是可行的)
这意味着你没有覆盖的访问过的链接的功能。
code 的:
TextView的contactWeb1 =(TextView中)findViewById(R.id.contactWeb1);
desc字符串=<字体颜色= \红\>< A HREF =HTTP://www.mysite.com/'>访问我的网站< / A>< / FONT>中;
contactWeb1.setText(Html.fromHtml(降序));
contactWeb1.setMovementMethod(LinkMovementMethod.getInstance());
I am using Linkify
in my app, and visited link text is appearing as dark purple. My overall layout background color is dark blue so this is impossible to read. The text is set as white, but visited links are appearing as dark purple. How do I override this?
<TextView android:text="Website:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14dip"
android:paddingBottom="2dip"
android:background="#ffffff"
android:textColor="#577dbe" />
<TextView android:text="http://www.mysite.com/"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dip"
android:paddingBottom="6dip"
android:textColor="#ffffff"
android:id="@+id/contactWeb1" />
It turned out to be a simple solution!
However you won't be able to do the visited
/ not visited
differentiation.
TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1);
noteView.setText("http://www.blablaasd.com/");
noteView.setLinkTextColor(Color.red); //for example
Linkify.addLinks(noteView, Linkify.ALL);
My attempts to catch visited states:
Use
noteView.setLinkTextColor(getResources().getColorStateList(R.color.colors));
Instead of
noteView.setLinkTextColor(Color.red);
In res/
create folder color
and create colors.xml
in res/color/
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="true" android:color="#00ff00">
</item>
<item
android:state_window_focused="true" android:color="#00ff00">
</item>
<item android:color="#FF00ff"/>
</selector>
I have tried my best to catch visited states. I tried all the states a selector can take.
I might have missed In case you found out, share (:
ALTERNATE SOLUTION (works only for html links)
Set the font Color programatically
Drawback (Be carefull for this point)
You will have to catch whether it was visited or not (this is doable)
This means that you are not overriding the visited links functionality.
CODE:
TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1);
String desc = "<font color=\"red\"><a href='http://www.mysite.com/'>Visit my site</a></font>";
contactWeb1.setText(Html.fromHtml(desc));
contactWeb1.setMovementMethod(LinkMovementMethod.getInstance());
这篇关于Android的Linkify链接文字颜色忽略,CSS样式将覆盖可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!