我在网页视图中显示了一些内容,该视图以<p>
开头,以</p>
标记结尾。我正在通过loadDataWithBaseURL将内容加载到webview中并尝试在中间显示内容:
public static String contentPrefix = "<html><head><style type='text/css'>#content_wrapper {position: relative; margin: 0px auto;} </style></head><div id='content_wrapper'>";
public static String contentPostfix = "</div></html>";
webView.loadDataWithBaseURL("", contentPrefix + result + contentPostfix, "text/html", "UTF-8", "");
但它不起作用。如何在中间显示内容?
答案 0 :(得分:2)
最后它有效!
String desiredContent = "my test html";
String strBody = "<html>"
+ "<head>"
+ " <style type=\"text/css\">"
+ " @font-face "
+ " { font-family: Tahoma;"
+ " src:url(\"~/android_asset/fonts/MyriadPro-Regular.otf\") "
+ " }"
+ " #text"
+ " { font-family: Tahoma;"
+ " font-size:14;"
+ " text-align: center;"
+ " }"
+ " </style>"
+ ""
+ "</head>"
+ "<body dir=\"rtl\" id=\"text\">"
+ desiredContent
+ " </body></html> ";
myWebView.loadDataWithBaseURL(null, strBody, "text/html", "utf-8",
null);
答案 1 :(得分:0)
尝试:
public static String contentPrefix = "<html><head><style type=\"text/css\">p{text-align:center;}</head>";