0

I want to customize text (font, size, color...) which is displayed on a picture. I decided to use WebView as I'm not sure how to use (and is it possible at all???) HTML/CSS inside a TextView. The problem is that a WebView has its own background(white) though which I can't see my picture. setBackgroundDrawable(null); did not help.

lomza
  • 9,412
  • 15
  • 70
  • 85

4 Answers4

2

Use an imageview and textview inside of an absolutelayout or relativelayout. Then align the two views to different sides of the layout and use margins and gravity to space them correctly. Using a webview for images and text when there is no need seems pointless if they are not on a webpage.

http://developer.android.com/resources/articles/layout-tricks-merge.html

To add a font to your project, create a new folder called "assets" in your root. inside there creates a folder "fonts" and in there, place your .ttf file. Here is a link:

How to add external fonts to android application

Community
  • 1
  • 1
Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75
  • OK, I understand your point. But if I want to set a custom font with text aligned as I want, with spaces and the like, would I be able to do all this with a TextView? – lomza May 14 '11 at 09:42
  • Do you have a screen shot or something? you can add .ttf fonts to your app if you like. – Anthony Graglia May 14 '11 at 12:54
0

You might be able to use yourWebView.setBackgroundResource(R.drawable.yourImage); But I am not 100% sure that WebViews support that method. Another option would be to put the Image in the html that you are using though. That might be the easiest way to go about making it look exactly how you want.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • It supports this method, but still no effect. Hmmm...I'm not sure about image in the html, but I will definitely try it if nothing will help. Thanks! – lomza May 13 '11 at 13:49
  • I have a question. How can I put an image, which is stored in drawables into HTML and display a text over that image? – lomza May 16 '11 at 07:56
  • I don't think you could do it with an image stored in the drawables folder. It would have to be in whichever folder your html document is. Assets probably. Or you could make a sub-folder like Assets->images. – FoamyGuy May 16 '11 at 13:11
0

You can try this out..

public class Hello extends Activity {   
    WebView mWebView;

/** Called when the activity is first created.     */
        @Override  
    public void onCreate(Bundle savedInstanceState)   
{
        super.onCreate(savedInstanceState);

        setContentView(R.layout.hello);
        mWebView = (WebView) findViewById(R.id.webviewactive);

String text =  


 mWebView.loadData(text, "text/html", "utf-8");   
 mWebView.setBackgroundColor(0);
Marc Bernstein
  • 11,423
  • 5
  • 34
  • 32
0

OK, so I found the answer. If you want to make the background of WebView transparent, just write in your .xml file android:alpha="0". To retrieve HTML-tags in Android, implement a TagHandler interface. There is an example here.

lomza
  • 9,412
  • 15
  • 70
  • 85