HTML Text in WebView Android

XML File

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Activity Class

public class HtmlWebViewActivity extends AppCompatActivity{

    private WebView webView;

    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        webView = (WebView) findViewById(R.id.webView);

        showHtmlWebView();
    }

    private void showHtmlWebView() {
        final String mimeType = "text/html";
        final String encoding = "UTF-8";
        String htmlString = "<html>\n" +
                "<body>\n" +
                "<center>\n" +
                "<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif' />\n" +
                "<p>Hello World </p>\n" +
                "<font color='#60c000' size='4'><strong>Android Developer</strong></font>\n" +
                "<p>Android powers hundreds of millions of mobile devices in more than 190 countries around the world. It's the largest installed base of any mobile platform and growing fast—every day another million users power up their Android devices for the first time and start looking for apps, games, and other digital content.</p>\n"+
                "<p>Android gives you everything you need to build best-in-class app experiences. It gives you a single application model that lets you deploy your apps broadly to hundreds of millions of users across a wide range of devices—from phones to tablets and beyond.</p>\n"+
                "</center>\n" +
                "</body>\n" +
                "</html>\t\t ";

        webView.loadData(htmlString, mimeType, encoding);
    }
}

View Image

Share this if like this post

No comments:

Post a Comment

Privacy Policy

What information do we collect? – We may collect information such as device name, device id, client user-agent for advertising. What ...