我的 Activity 由 long textview 组成,必须用水平彩色线(分隔符)分隔为多个段落,我使用 webview 允许添加:
<div html tag
我在谷歌搜索后发现这段代码形成了一个彩色水平线分隔符,但是当我将它应用到 WebView 时它不起作用,如下所示:
<div class="aligncenter" style="width:400px;height:0;border-top:2px solid #FF7500;font-size:0;"></div>
我将如下应用到 webview,但它不起作用:
公共(public)类 WebViewActivity 扩展 Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
String customHtml = "<body><h1>Heading Text</h1><p>This is example " +
"<strong>HTML </strong>tag in webviw . </p>" +
"<div class="aligncenter" style="width:400px;height:0;
border-top:2px solid #FF7500;font-size:0;"></div>" ;
webView.loadData(customHtml, "text/html", "UTF-8");}
也尝试如下不工作:
String customHtml = "<body><h1>Heading Text</h1><p>This is example " +
"<strong>HTML </strong>tag in webviw . </p>" +
"<div class=aligncenter style=width:400px;height:0;border-
top:2px solid #FF7500;font-size:0;></div>" ;
webView.loadData(customHtml, "text/html", "UTF-8");}
}
任何关于如何在 webview 中添加 div html 标签的建议将不胜感激,谢谢。
最佳答案
尝试在字符串中使用 param = 'value' 而不是 param = "value"。
像这样:
String customHtml = "<body><h1>Heading Text</h1><p>This is example " +
"<strong>HTML </strong>tag in webviw . </p>" +
"<div class='aligncenter' style='width:400px;height:0;
border-top:2px solid #FF7500;font-size:0;'></div>" ;
顺便说一句,你在 css 的某个地方设置了 aligncenter 类吗?
关于android - 字符串 webview 中的 html 标签 <div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16250102/