如何加载文本在网页视图的Android? [英] How To Load Text In Webview Android?
本文介绍了如何加载文本在网页视图的Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要显示HTML文本,但没有图像保存load.when在HTML文件中的文本资产文件夹的图像是显示。
I want show html in text,but images not load.when save text in html file in asset folder images is display.
String html="<html><head></head><body> <Marquee><img src="\mnt\sdcard\osVodigi\Images\apps.png"/><img src="\mnt\sdcard\osVodigi\Images\shop.png"/><img src="\mnt\sdcard\osVodigi\Images\skype.png"/><img src="\mnt\sdcard\osVodigi\Images\word.png"/></marquee>sfdfsd</body></html>";
web.loadData(html, "text/html", "utf-8");
如何解决我Problms?
谢谢
How I Resolve Problms? thanks
推荐答案
您需要获得图像的路径,然后使用映像路径在HTML和web视图加载它。
You need to get the path of image and then use the image path in html and load it in webview.
不要使用硬codeD路径中使用 Environment.getExternalStorageDirectory()
。
Don't use hard coded path use Environment.getExternalStorageDirectory()
.
同时检查SD卡安装
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
//dosomething
}
要获取路径和负载图像中的WebView
To get the path and load image in webview
File f= new File(Environment.getExternalStorageDirectory(),"MyFolder");
String filename ="image.png"
String imagePath = "file://"+ f.getAbsolutePath() + File.separator + filename;
String html = "<html><head></head><body><Marquee><img src=\"" + imagePath + "\">My Scroll Text</Marquee></body></html>";
wv= (WebView) findViewById(R.id.wv);
wv.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
添加权限清单文件
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
快照。图像与文中滚动
Snap shot. The image and the text does scroll
这篇关于如何加载文本在网页视图的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文