Android在Dialog中使用Html

来源:互联网 发布:郑州大学网络管理中心 编辑:程序博客网 时间:2024/06/01 07:54

发现mini飞信的使用帮助和更新日志使用的是一个Dialog中显示html文件中的内容,而且QQ的关于也是使用的HTML文件

自己也想实现类似效果

然后google:

http://stackoverflow.com/questions/1955043/android-html-container

EboMike提供的方法,这个只是使用Html代码,并不是把一个html文件当做资源来引用:

.setMessage(Html.fromHtml("<b>Bold text</b> <i>and italics</i>"))  

发现Html文件需要放在assets文件夹下,查了下assets文件夹的用途找到这两篇:

http://www.cnblogs.com/stay/articles/1898965.html (Android读取assets目录下的资源)

http://blog.csdn.net/gsg8709/article/details/7326745  (android 文件读取(assets))

原来应该这么用:

WebView.loadUrl(“file:///android_asset/sample.html”); 

 

然后,Android 开发文档:WebView

http://developer.android.com/reference/android/webkit/WebView.html

 

然后,参考了这篇博文:android中使用html作布局文件,非常感谢dinglang_2009,给了很大启发

http://blog.csdn.net/dinglang_2009/article/details/6862627

 

其实,在http://stackoverflow.com/questions/1955043/android-html-container

JRL已经给了解决方案,只是自己没有注意到:

"Not sure what you're trying to do, but WebView handles HTML."

又仔细看了下,使用webview来加载htnl文件其实是有延迟的,我就用它来显示使用帮助和更新日志这类东西的,效果很好。

 

最后就是实现了,要自定义Dialog,两篇很好的参考文章:

http://griffinshi.iteye.com/blog/568409

http://www.oschina.net/question/12_35723

 

使用百度,输入android dialog html 会得到这样一篇文章

http://shareandopen.tumblr.com/post/12598945632/open-local-html-file-in-custom-dialog

 

Done!

Enjoy~

 

原创粉丝点击