2014-02-13 34 views
0

我在webview中显示了一些内容,该内容以<p>开头并以</p>标记结尾。我正在通过loadDataWithBaseURL将内容加载到webview中,并尝试在中间显示内容:如何将中心的内容与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", ""); 

但它不起作用。我应该怎么做才能在中间显示内容?

回答

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); 
0

尝试:

public static String contentPrefix = "<html><head><style type=\"text/css\">p{text-align:center;}</head>";