1
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<TextView
    android:id="@+id/htmlText"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textColor="#FFCC00" />

</FrameLayout>

If I set textview's text like this:

setText(Html.fromHtml(htmlString));

scroll does not work. Moreover, if in html there's an img tag, image is not viewed..why?

edit:

I switched to webview:

WebView view = (WebView)findViewById(R.id.newsView);
view.loadData(htmlString,"text/html","UTF-8");

and now I solved these problems, but I still got others:

1)How to set transparent background so I can see my app's one?

2)How to set foreground text color so, again, I can see my app's colors?

3)If there's an img tag image does not fit the view, leading to an horizontal scrolling. Text, instead, perfectly fills.

user1610075
  • 1,583
  • 3
  • 15
  • 32
  • 1. See http://stackoverflow.com/q/5003156/1321873 2. Set using HTML formatting 3. See http://stackoverflow.com/q/3099344/1321873 – Rajesh Sep 06 '12 at 09:20

2 Answers2

1

If you want to display HTML content, use WebView. TextView supports only limited set of HTML tags - mainly for formatting text.

Rajesh
  • 15,724
  • 7
  • 46
  • 95
  • It works! There's still a little catch: I'd like to manually set background and text color, to adapt html to my app ui..is it possibile? – user1610075 Sep 06 '12 at 08:52
  • Another problem is about coding: in my html I often use "è","à","ì",... and, although setting coding to "iso 8859-1" it still does not display them – user1610075 Sep 06 '12 at 08:58
  • Can you please post your code? Update your question and add the code used to load the HTML in WebView. – Rajesh Sep 06 '12 at 09:09
1

You can use ScrollView for the textView and it becomes scrollable. And then use

htmlText.setText(Html.fromHtml(htmlString));

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true" >

        <TextView
            android:id="@+id/htmlText"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </ScrollView>
</RelativeLayout >
Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59
César Cobo
  • 598
  • 5
  • 9