2012-02-29 106 views
0

我希望以合理的格式显示我的文本,为此,我使用了webview而不是textview。这里我的问题是我想为我的webview添加背景图片。文字内容在我的string.xml中。我用下面的代码,如何为android webview设置背景图片?

<string name="link"> <![CDATA[ 
    <html> 
<head></head> 
<body style="text-align:justify;color:white;background-color:black;"> 

// content 
    </body> 
</html> 

    ]]> 
    </string> 

在这段代码中,我将背景颜色设置为黑色,而不是我希望添加.jpg或.png图像。我如何修改此代码。提前致谢。

+0

http://stackoverflow.com/questions/4534043/android-add-image-to-webview-from-a-drawable – 2012-02-29 11:02:19

+0

为什么你要使用的WebView而不是TextView的? [试试这个](http://stackoverflow.com/questions/1292575/android-textview-justify-text) – 2012-02-29 11:20:02

+0

在文本视图中,文本(这里我用了一段)是不合理的,这就是为什么我使用webview 。 – Aerrow 2012-02-29 11:50:03

回答

1

在第一次你应该把你的图像在res/drawable。 然后改变你的代码

<body style='text-align:justify' background="file:///android_res/drawable/a1.jpg" > 
1

对于您必须set background image in xml

  <WebView 
      android:id="@+id/webView" 
      android:layout_width="fill_parent" 
      android:layout_height="40dp" 
      android:background="@drawable/ic_launcher" 
      android:scrollbars="none" /> 

你必须set transparent background color活动声明之后。

  WebView webView= (WebView) findViewById(R.id.webView); 
      webView.setBackgroundColor(Color.TRANSPARENT);