Kit*_* Ng 29 html android webview
在使用WebView时,我们通常会为其添加一个URL:
WebView.loadUrl(myURL);
Run Code Online (Sandbox Code Playgroud)
但是可以直接放入HTML代码吗?因此它将符合以下逻辑:
WebView.loadContent ( <html><head><script></script></head><body>....</body></html> );
Run Code Online (Sandbox Code Playgroud)
谢谢.
Ter*_*rel 51
看看这个:http: //developer.android.com/reference/android/webkit/WebView.html
// OR, you can also load from an HTML string:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
Run Code Online (Sandbox Code Playgroud)
mjo*_*osh 12
String yourhtmlpage = "<html><body>You scored <b>hello world</b> points.</body></html>";
webview.loadDataWithBaseURL(null, yourhtmlpage, "text/html", "UTF-8", null);
Run Code Online (Sandbox Code Playgroud)
试试这个代码.这个对我有用.
WebSettings settings = mDesc.getSettings();
settings.setDefaultTextEncodingName("utf-8");
mDesc.loadData(mDescText, "text/html; charset=utf-8",null);
Run Code Online (Sandbox Code Playgroud)