2013-04-04 15 views
13

sto ottenendo questo contenuto HTML in risposta tramite la variabile: String mresult=WebView carico Html Content

<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> 

non poteva caricare webview, devo provare a caricare in questo modo:

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

ancora webview visualizza una pagina bianca vuota.

Nel file xml:

<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" /> 

nell'attività:

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); 
+3

Il codice funziona nel mio emulatore. –

risposta

2

non so y ancora non si carica in webview ma il risultato dato è visualizzato in TextView nel formato Html come

TextView txtweb = (TextView) findViewById(R.id.txtweb); 
txtweb.setText(Html.fromHtml(mresult)); 
2

provare questo codice per il WebView:

WebView wv = (WebView) findViewById(R.id.webView); 
wv.setWebViewClient(new WebViewClient() { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     view.loadUrl(url); 
     return true; 
    } 
}); 
wv.loadData(mresult, "text/html; charset=UTF-8", null); 
+0

non caricare ancora i dati –

+0

qui viene visualizzato solo il browser bianco vuoto –

+0

controllare la larghezza/altezza della visualizzazione Web nel proprio XML oppure, se è tramite codice, è necessario aggiungere i parametri di layout. magari incolla l'intero codice per vedere se ci sono altri possibili problemi. –

22

Utilizzare questo Html_value in questo modo:

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>"; 

questo viene utilizzato in WebView solo allora funzionerà perché il tag HTML non è stato chiuso correttamente:

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

uscita:

enter image description here

+0

ok ma per aggiungere \ –

+0

mresult.replaceAll ("\" "," \ ""); –

+0

e non visualizzare ancora –

3
wb.loadDataWithBaseURL("", result, "text/html", "UTF-8", ""); 
0

Utilizzare questa:

webView.loadDataWithBaseURL("file:///android_asset/", htmlParsing, "text/html", "utf-8", null); 
    webView.getSettings().setAllowFileAccess(true); 

in htmlparsing: basta passare Urs codice HTML.

Funziona ....

Problemi correlati