gpt4 book ai didi

android - 在android中将对齐设置为html字符串的子字符串

转载 作者:行者123 更新时间:2023-11-29 00:30:36 27 4
gpt4 key购买 nike

我正在开发一个应用程序,它需要对齐 html 字符串的子字符串。

问题:我使用 webview 通过以下代码设置 html 文本的对齐方式

String htmlText = "<html><body style=\"text-align:justify\"> %s </body></Html>";
WebView webView = new WebView(SubProducts.this);
webView.loadData(String.format(htmlText, description), "text/html", "utf-8");

但是当我像这样为子字符串设置相同的想法时:

String htmlText = "<html><body style=\"text-align:justify\"> %s </body></Html>";
WebView webView = new WebView(SubProducts.this);
webView.loadData(String.format(htmlText, description.substring(1,170)), "text/html", "utf-8");

在我的输出文本中 html 文本(

<html><body style=\"text-align:justify\"> %s </body></Html>) 

也是可见的。如何实现这一点。有人可以帮助我吗?提前致谢。

最佳答案

在 WebView 中找到 Substring 并加载,这对我来说很好用。为了证明现成的代码如下所示

    public static void loadHtmlContentForAboutUs(WebView view, String appendText) {
String s = "<html><head><style type='text/css'>body {margin:0px;color:707070;"
+ "text-align: justify;}</style></head><body>"
+ appendText
+ "</body></html>";

view.loadDataWithBaseURL("", s, "text/html", "utf-8", null);
view.setBackgroundColor(Color.TRANSPARENT);
}

关于android - 在android中将对齐设置为html字符串的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16030496/

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