1

I wish to show my text as in justified format, for this purpose i used webview instead of textview. Here my problem is i wish to add background image for my webview. The text content are in my string.xml. i used the following code,

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

// content 
  </body>
</html>

    ]]>
    </string>

in this code i set background color as black, instead of that i wish to add an .jpg or .png image. How can i modify this code. Thanks in advance.

Aerrow
  • 12,086
  • 10
  • 56
  • 90
  • http://stackoverflow.com/questions/4534043/android-add-image-to-webview-from-a-drawable – Samir Mangroliya Feb 29 '12 at 11:02
  • Why do you want to use WebView instead of TextView ? [try this](http://stackoverflow.com/questions/1292575/android-textview-justify-text) – Rashmi.B Feb 29 '12 at 11:20
  • in text view, the text (here i used a paragraph) is not justify, that's why i'm using webview. – Aerrow Feb 29 '12 at 11:50
  • 2
    WebViews does not have background attribute, however you can implement a RelativeLayout and put an ImageView over the Webview and set the a transparency with alpha so it doesnt disturbs the content of the Webview, also consider it putting it attribute clickable to false for the ImageView and you should be all set. – Raykud Jun 13 '12 at 17:23

2 Answers2

2

at frist you should put your image in res/drawable. then change your code

<body style='text-align:justify' background="file:///android_res/drawable/a1.jpg" >
ghader
  • 369
  • 3
  • 9
2

For that you have to 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" />

After Declaring in activity you have to set transparent background color.

            WebView  webView= (WebView) findViewById(R.id.webView);
            webView.setBackgroundColor(Color.TRANSPARENT);
Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95