2014-05-12 115 views
0

所以在Android中,我想证明文字的合理性,所以我决定使用Webview.It工作正常,但唯一的问题是我的应用程序的背景不是白色的。所以每当我看到文字时,它总是有一个白色的背景。那么我可以添加一个body标签来使它能够改变背景颜色吗?需要Android字符串HTML帮助

String text = "<html><body style=\"text-align:justify\"> %s </body> </Html> "; 
    // I want to include a body tag above which will make the background this color = #e6e6e6 
     String data = "My Text"; 

     WebView webView = (WebView) findViewById(R.id.WebView); 
     webView.loadData(String.format(text, data), "text/html", "utf-8"); 

回答

1

看看下面的链接。 Android TextView Justify Text

它解释了android中的对齐规则。如何在webview中做到这一点,它也有一个支持库,你可以用它来做本地的。

尝试

webView.setBackgroundColor("#00000000") 

为透明背景。

0

尝试:

String text = "<html><body style=\"text-align:justify; background-color:#e6e6e6;\"> %s </body></html>" 

background-color CSS属性应该让你设置任何你希望它是背景。

编辑:Kalel Wade的回答是更好的,因为它是通过Android属性完成的,而不是HTML。