如何获得drawable或“.gif”的路径在android中 [英] How to get the path of a drawable or ".gif" in android

查看:91
本文介绍了如何获得drawable或“.gif”的路径在android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将HTML字符串传递给webview,如下所示

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)+ //这是我想要本地化的字符串
< / font> +

< br /> +
< br /> +
< br /> +
< br /> +
< br /> +
< img src = \+
loading.gif+ //这个GIF我要通过
\> +
< / td> +
< / tr> +
< / table> +
< / body> +
< / html>;
webview.loadData(data,text / html,UTF-8);

一切正常,但是gif没有加载。
只有传递html的原因是本地化该字符串loading.Earlier它在资产中,字符串Loading在html文件中被硬编码。现在我通过获取字符串资源(getResources()。getString(R.string.loading))来传递它。问题是传递GIF。

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 coded in html file. now I am passing it by getting getting string resources (getResources().getString(R.string.loading)). Problem is passing "GIF".

请帮我解决这个问题。

推荐答案

您的问题的一个解决方案是,将所有HTML代码保存到文件中,并将该文件与图像(gif)文件一起放在资源文件夹中。然后只需在WebView中加载该HTML文件即可。如果要在HTML中添加任何运行时值,请在HTML中添加一些占位符字符串,并在运行时使用String.format()替换它们。这样,您必须使用loadDataWithBaseURL()方法来显示内容。

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.

这篇关于如何获得drawable或“.gif”的路径在android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆