MainActivity.java
====================
package com.sam.web.htmldemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
private WebView webView;
String myText="<h1>This is heading 1 </h1> "+
"<h2>This is heading 2 </h2> "+
"<h3>This is heading 3 </h3> "+
"<p>This is a paragraph</p> "+
"<p><u>This is a an uderline</u> </p> "+
"<p><b>This is a bold text</b> </p> "+
"<p><i>This is a an italic</i> </p> "+
"programming language order list "+
"<ol> "+
"<li>C </li> "+
"<li> C++</li> "+
"<li> Java</li> "+
"</ol> "+
"(a+b)<sup>2</sup>=a<sup>2</sup>+2ab+b<sup>2</sup>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.webViewId);
webView.loadDataWithBaseURL(null,myText,"text/html","utf-8",null);
}
}
=================================================================================
activity_main.xml
==================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#22ffb2"
android:padding="5dp"
tools:context="com.sam.web.htmldemo.MainActivity">
<WebView
android:id="@+id/webViewId"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</LinearLayout>
============================================================================================
============================================================================================
HTML in TextView
================
MainActivity.java
=====================
package com.sam.web.htmldemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.webkit.WebView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView textView;
String myText="<h1>This is heading 1 </h1> "+
"<h2>This is heading 2 </h2> "+
"<h3>This is heading 3 </h3> "+
"<p>This is a paragraph</p> "+
"<p><u>This is a an uderline</u> </p> "+
"<p><b>This is a bold text</b> </p> "+
"<p><i>This is a an italic</i> </p> "+
"programming language order list "+
"<ol> "+
"<li>C </li> "+
"<li> C++</li> "+
"<li> Java</li> "+
"</ol> "+
"(a+b)<sup>2</sup>=a<sup>2</sup>+2ab+b<sup>2</sup>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=(TextView) findViewById(R.id.textViewId);
textView.setText(Html.fromHtml(myText));
}
}
===========================================================================================
activity_main.xml
=================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#22ffb2"
android:padding="5dp"
tools:context="com.sam.web.htmldemo.MainActivity">
<TextView
android:textSize="17sp"
android:id="@+id/textViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
thistimebd Bangladesh Live online newsportal, education, Lifestyle, Health, Photography, gif image etc.
Make your own name or company name website | contact: thistimebd24@gmail.com
Copyright © 2020-2024 News Portal in Bangladesh - THISTIMEBD.COM. ALL Rights Reserved.