机器人的WebView链接颜色机器人、颜色、链接、WebView

2023-09-08 09:29:50 作者:风过思念散

我使用的WebView显示我的应用程序内的网站,我想知道是否有可能改变链接颜色和样式默认情况下是蓝色并带有下划线?

I am using WebView to show websites inside my application, and I was wondering is it possible to change link color and style which is by default blue and underlined?

我搜索了一下,但也有所有的问题和解决方案有关删除的亮点周围的链接,没有任何链接本身。我只是想知道有没有一些解决方案容易,因为TextView中的安卓?textColorLink 或我需要以某种方式改变网站身体

I searched about it but there are all questions and solutions about removing the highlight around the link, nothing about the link itself. I just want to know is there some solution as easy as TextView's android:textColorLink or will I need to alter the website body somehow?

谢谢!

推荐答案

好吧,我设法做到这一点,并希望分享我的方式为未来的访客。

Okay, I managed to do it and wanted to share my way for the future visitors.

首先,我创建了所需的样式,名为css文件的style.css ,根据资产的文件夹保存

First I created a css file with the desired style, named style.css, saved under assets folder

a {color:purple; text-decoration:none}

那么,在code我加载页面,如下所示,其中内容是页面的实际HTML内容

Then, in the code I loaded the page as follows where content is the actual html content of the page

String htmlBody = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + content;
mWebView.loadDataWithBaseURL("file:///android_asset/", htmlBody, "text/html", "utf-8",
            null);

这就是它!希望它可以帮助别人。

That's it! Hope it helps somebody.