gpt4 book ai didi

Android,如何将 CSS 应用到 WebView 中?

转载 作者:太空狗 更新时间:2023-10-29 15:35:26 25 4
gpt4 key购买 nike

我想使用 WebView,以便向用户显示一些段落。在 XML 中,我编写了以下代码:

<WebView
android:id="@+id/webview"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:background = "#190306"
android:textColor = "#FFDEC2"
android:autoLink = "web" />

但是背景、文本颜色和自动链接无法识别,模拟器显示的 webview 具有白色背景和黑色文本颜色。

如何将 CSS 应用到这个 webview 中?谢谢

最佳答案

我在 Activity 中添加了以下代码,现在运行良好。

final WebView page = (WebView) findViewById(R.id.webview);
String text = "<html><head>"
+ "<style type=\"text/css\">body{color: #ffdec2; background-color: #1F0C01;}"
+ "</style></head>"
+ "<body>"
+ "<p align=\"justify\">"
+ getString(R.string.intro_content)
+ "</p> "
+ "</body></html>";

page.loadData(text, "text/html", "utf-8");

关于Android,如何将 CSS 应用到 WebView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6014519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com