Friday, May 20, 2011

Android HTML Text View; a simple explination.

To create a simple HTML text view copy the code below to your java code associated with your layout view.

TextView TextHTML = (TextView) findViewById(R.id.TextHTMLview);
TextHTML.setMovementMethod(LinkMovementMethod.getInstance());
String text =
"Visit my <a href='http://reddingtech.com'>website</a>";
 TextHTML.setText(Html.fromHtml(text));


Next you must define the strings to associate both the text and view container to populate the html text located in your java resource that we just created.

Open your layout view and add the following TextView

<TextView
android:id="@+id/TextHTMLview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@+id/TextHTML"
android:textSize="14dp"
android:gravity="left"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>

No comments:

Post a Comment