其他分享
首页 > 其他分享> > 我如何设置autoLink =“ web”链接的样式?

我如何设置autoLink =“ web”链接的样式?

作者:互联网

我有以下TextView:

<TextView android:id="@+id/theFooBar"
          android:autoLink="web"
          android:layout_height="wrap_content"
          android:layout_width="fill_parent"
          android:text="@string/fooBar"
          android:textColor="@android:color/black"
          android:textSize="20sp"/>

和字符串:

<string name="fooBar">Foo <u>bar</u>.</string>

这给了我带黑色下划线的文字.如果我希望链接的蓝色非下划线文本(“ bar”部分),但我希望其余部分(“ foo”部分)为黑色怎么办?我该如何实现?

解决方法:

我建议您在这种情况下使用WebView代替TextView:

WebView web = (WebView) findViewById(R.id.theFooBar);
String str = "<font color='blue'>bar</font><font color='black'><u>foo</u></font>";
web.setBackgroundColor(0);
// It will sets the background color from white to transparent. 
web.loadData(str, "text/html", "utf8");

标签:android-layout,hyperlink,styling,android,textview
来源: https://codeday.me/bug/20191102/1992875.html