Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does web view Load Html Content?

I am getting this html content in Response via the variable: String mresult=

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Lorem Ipsum</title>
</head>
<body style="width:300px; color: #00000; ">

<p><strong> About us</strong> </p>
<p><strong> Lorem Ipsum</strong> is simply dummy text .</p>

<p><strong> Lorem Ipsum</strong> is simply dummy text </p>

<p><strong> Lorem Ipsum</strong> is simply dummy text </p>

</body></html>

It could not load in webview, I have to try to load it like this:

web.loadDataWithBaseURL(null, mresult, "text/html", "UTF-8", null);

still webview displays a Blank white page.

In the xml file:

<WebView
        android:id="@+id/wV"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"          
        android:layout_margin="10dp"
        android:background="@android:color/transparent"
        android:cacheColorHint="#00000000" />

In the Activity:

String mresult="Here my given data";
WebView web = (WebView)findViewById(R.id.wV);
web.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
});
web.loadData(mresult, "text/html; charset=UTF-8", null);
like image 856
Ankitkumar Makwana Avatar asked Apr 04 '13 07:04

Ankitkumar Makwana


People also ask

How to load HTML content in Android WebView?

This example demonstrate about How to load html content in android webview. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken web view to show html content.

Is it possible to get the rendered page from WebView?

Works for android 4.2 and ABOVE. Android WebView is just another render engine that render HTML contents downloaded from a HTTP server, much like Chrome or FireFox. I don't know the reason why you need get the rendered page (or screenshot) from WebView. For most of situation, this is not necessary.

Why is my HTML tag not working in WebView?

this is used into webview then only it will work because your html tag was not properly closed: WebView browser = (WebView) findViewById (R.id.sample); browser.getSettings ().setJavaScriptEnabled (true); browser.loadData (html_value, "text/html", "UTF-8");

Why is my WebView not showing up on my screen?

check for the width/height of the webView in your XML, or if it is via code, you should add layout parameters. maybe paste the whole code to see if there are any other possible problems.


1 Answers

Use this Html_value in this way:

String html_value = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>Lorem Ipsum</title></head><body style=\"width:300px; color: #00000; \"><p><strong> About us</strong> </p><p><strong> Lorem Ipsum</strong> is simply dummy text .</p><p><strong> Lorem Ipsum</strong> is simply dummy text </p><p><strong> Lorem Ipsum</strong> is simply dummy text </p></body></html>";

this is used into webview then only it will work because your html tag was not properly closed:

WebView browser = (WebView) findViewById(R.id.sample);
        browser.getSettings().setJavaScriptEnabled(true);
        browser.loadData(html_value, "text/html", "UTF-8");

output:

enter image description here

like image 156
balaji Avatar answered Sep 21 '22 19:09

balaji