HTML 字符串到 webview
HTML string to webview
我想创建一个 android 应用程序,
apk 可能有一个文本框和一个按钮。
在文本框中,用户将输入他们的 HTML codes/strings。
通过单击按钮,它将显示他们从文本框中键入的代码的输出。
调用此行:
wv.loadData(yourHtmlData, "text/html", "UTF-8");
你可以这样做
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.WebView01);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework" +
"help help with homework homework assignments elementary school high school middle school" +
"// --><font color='#60c000' size='4'><strong>Please!</strong></font>" +
"<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif' />";
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
}
在清单中添加这个
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
我想创建一个 android 应用程序,
apk 可能有一个文本框和一个按钮。
在文本框中,用户将输入他们的 HTML codes/strings。 通过单击按钮,它将显示他们从文本框中键入的代码的输出。
调用此行:
wv.loadData(yourHtmlData, "text/html", "UTF-8");
你可以这样做
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.WebView01);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework" +
"help help with homework homework assignments elementary school high school middle school" +
"// --><font color='#60c000' size='4'><strong>Please!</strong></font>" +
"<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif' />";
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
}
在清单中添加这个
<uses-permission android:name="android.permission.INTERNET"></uses-permission>