Android:如何获取可绘制图像名称 [英] Android: How to get Drawable Image name
问题描述
我想获取可绘制图像的名称并将该名称存储在一个字符串中.例如,对于图像,我可能会使用名为 play.png 或 stop.png 的 .png 文件.我只想知道drawable中的哪个图像用于ImageView..有没有办法获得drawable的名称/(??.png)
I want to get the name of the drawable image and want to store that name in a string. For example , for an Image, I might use a .png file named play.png or stop.png. I just want to know which image in drawable is used for the ImageView.. Is there any way to get the name of the drawable/(??.png)
谢谢.
推荐答案
我不认为有任何直接的方法可以获取可绘制图像的名称,除非您将图像名称与图像一起存储.
I donot think there is any direct way to get name of drawable image unless you stores the image name along with image.
在 XML 中,您可以执行以下操作将图像名称设置为图像视图的附加数据
In XML you can do the following to set image name as an additional data to imageview
android:tag="btful.png"
以编程方式设置图像名称
Programmetically setting imagename
ImageView img = (ImageView) findViewByID(R.id.img)// my image
img.settag("btful.png"); // to set an image name
您可以使用 getTag() 获取图像名称
you can get the image name by using getTag()
String imageName = (String)img.getTag();
这篇关于Android:如何获取可绘制图像名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!