Android中如何顯示本地HTML:
java代碼:
//one
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(“content://com.android.htmlfileprovider/sdcard/index.html”);
//two
Uri uri = Uri.parse(“content://com.android.htmlfileprovider/sdcard/01.htm”);
Intent intent = new Intent();
intent.setData(uri);
intent.setClassName(“com.android.htmlviewer”, “com.android.htmlviewer.HTMLViewerActivity”);
startActivity(intent);
//three
String encoding = “UTF-8″;
String mimeType = “text/html”;
final String html =”鏈接google“+”鏈接google“;
mWebView.loadDataWithBaseURL(“file://”, html,mimeType, encoding, “about:blank”);
復制代碼
Android開發:TextView中顯示HTML和圖片
最近有人咨詢我如何在TextView中顯示 html標簽內的圖片,大家都知道,在TextView中顯示HTML內容的方法如下所示:
1 TextView description=(TextView)findViewById(R.id.description);
2 description.setText(Html.fromHtml(item.getDescription()));
如果HTML中有圖片的話,顯示出來的圖片會被一個小框取代,那么怎么樣才能看到圖片呢?查看了一下API,android.text.Html還還有 另一個方法:Html.fromHtml(String source,ImageGetter imageGetter,TagHandler tagHandler),這個方法使用如下所示:
java代碼:ImageGetter imgGetter = new Html.ImageGetter() {
public Drawable getDrawable(String source) {
Drawable drawable = null;
Log.d(“Image Path”, source);
URL url;
try {
url = new URL(source);
drawable = Drawable.createFromStream(url.openStream(), “”);
} catch (Exception e) {
return null;
}
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
return drawable;
}
};
TextView description=(TextView)findViewById(R.id.description);
description.setText(Html.fromHtml(item.getDescription(),imgGetter,null));
復制代碼
Activity,
View,
HTML,
TextView,
顯示本帖地址: http://www.eoeandroid.com/thread-96720-1-1.html [復制鏈接]