开发者

How to get the path of a drawable or ".gif" in android

I am trying to pass a HTML string to webview as following

String data = "<html>" + "<body bgcolor=\"white \" align=\"center \" valign=\"center \">" + "<table width=\"470\" height=\"725 \" >" + "<tr>" + "<td align=\"center\" valign=\"center\">" + "<font color=\"gray\">" + getResources().getString(R.string.loading) + //this is the string i want to localize "</font>" +

"<br/>" + "<br/>" + "<br/>" + "<br/>" + "<br/>" + "<img src=\"" + "loading.gif" + //this the GIF i want to pass "\">" + "</td>" + "</tr>" + "</table>" + "</body>" + "</html>"; webview.loadData(data, "text/html", "UTF-8");

All works fine but that gif is not getting loaded. Only reason for passing html is to localize that string "loading".Earlier It was in assets and the string "Loading" was hard c开发者_C百科oded in html file. now I am passing it by getting getting string resources (getResources().getString(R.string.loading)). Problem is passing "GIF".

Please help me to resolve this.


One solution to your problem is, save all this HTML code in to a file and put that file in the asset folder along with the image (gif) file. Then simply load that HTML file in the WebView. If you want to add any runtime values in the HTML, then add some placeholder strings into your HTML, and replace them at runtime with String.format(). In this way, you have to use the loadDataWithBaseURL() method to show the contents.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜