2013-04-04 10 views
13

jestem coraz zawartość HTML w odpowiedzi za pośrednictwem zmiennej: String mresult=WebView obciążenia 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> 

Nie można załadować w webview, muszę spróbować załadować go tak:

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

nadal webview wyświetla pustą białą stronę.

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

w działalności:

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

Twój kod działa w moim emulatorze. –

Odpowiedz

2

nie wiem y nadal go nie ładuje w webview, ale podany wynik jest wyświetlany w TextView w formacie Html w formacie:

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

wypróbować ten kod dla 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

nadal nie ładuje danych –

+0

tutaj tylko wyświetlają pustą białą przeglądarkę –

+0

sprawdź szerokość/wysokość webView w swoim XML, lub jeśli jest za pośrednictwem kodu, powinieneś dodać parametry układu. może wkleić cały kod, aby zobaczyć, czy są jakieś inne możliwe problemy. –

22

Używaj tego Html_value w ten sposób:

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

ten służy do WebView wtedy tylko to będzie działać, ponieważ tag HTML nie był prawidłowo zamknięty:

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

wyjściowa:

enter image description here

+0

ok ale dodać \ –

+0

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

+0

i nie wyświetlaj nadal –

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

Użyj tego:

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

w htmlparsing: wystarczy przejść urs kod HTML.

Działa ....

Powiązane problemy