为什么没有方法来获得资源名称从可绘制对象 [英] Why there is no method to get Resource Name from Drawable object

查看:105
本文介绍了为什么没有方法来获得资源名称从可绘制对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从任何资源,我们可以使用下面的code创建可绘制对象(我的形象的名字arrow_selected.png)

To create Drawable object from any resource we can use the following code (my image name is arrow_selected.png)

Drawable d =getResources().getDrawable(R.drawable.arow_selected);

但后来我想从这个可绘制对象获取的资源名称的应用程序。 我因此未找到任何方法来获取资源的名称,比如下面的

But later in the application I want to get the resource name from this drawable object. I didnot find any method to get resource name like the following

d.getResourceName();

为什么没有在Android的API没有这样的方法。 我怎样才能获得资源名称从可绘制对象?

推荐答案

在情况下,如果你真的需要这种功能(我不知道你这样做),你可以创建自己的类扩展可绘制对象类,并在收到资源ID paremeter constructo的。

In case if you really need that functionality (I'm not sure you do), you could create your own class that extends Drawable class and receives Resource ID in paremeter of constructo.

然后,你需要存储此渣油特殊fiels在你的类并实现getter和setter FOT这一领域。瞧!

Then you need to store this ResID in special fiels in your class and implement getter and setter fot that field. Voila!

这篇关于为什么没有方法来获得资源名称从可绘制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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