loadDataWithBaseURL(baseUrl==null/"about:blank",……),baseUrl为null或"about:blank"指定相对路径.
WebView 主要调用三个方法:LoadUrl、LoadData、LoadDataWithBaseURL.
1、LoadUrl 直接加载网页、图片并显示.(本地或是网络上的网页、图片、gif)
2、LoadData 显示文字与图片内容 (模拟器1.5、1.6)
3、LoadDataWithBase 显示文字与图片内容(支持多个模拟器版本)
public class AboutView extends Activity implements OnTouchListener,
OnClickListener {
private Button btnAbout;
private WebView aboutBrowser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
btnAbout = (Button) this.findViewById(R.id.about_button);
aboutBrowser = (WebView) this.findViewById(R.id.about_webkit);
btnAbout.setOnTouchListener(this);
btnAbout.setOnClickListener(this);
// WebSettings s = aboutBrowser.getSettings();
// s.setUseWideViewPort(true);
// s.setJavaScriptEnabled(true);
// s.setBlockNetworkImage(true);
loadHTML();
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
@Override
public void onClick(View v) {
if(v == btnAbout) {
//这里是切换Activity
//注意:每个Activity都要在AndroidManifest.xml中注册
Intent i = new Intent();
i.setClass(AboutView.this, CiHaiView.class);
this.startActivity(i);
AboutView.this.finish();
}
}
public void loadHTML() {
String vStr = getText(R.string.vStr).toString();
String vNum = getText(R.string.vNum).toString();
final String htmlText = "<html>" +
"<head></head>" +
"<body>" +
"<br/>" +
"<table align=\"center\" border=\"0\" cellspacing=\"15\">" +
"<tr align=\"center\"><td><img src=\"file:///android_asset/edict.png\" /></td>" +
"<td>" +
"<b><font size=\"5\">" + vStr +"</font></b><br/>" + vNum +
"</td></tr>" +
"</table>" +
" " +
"</body></html>";
aboutBrowser.loadDataWithBaseURL("about:blank", htmlText, "text/html", "utf-8", null);
}
}