【问题标题】:Get the resource id from a drawable从可绘制对象中获取资源 id
【发布时间】:2012-12-13 18:27:43
【问题描述】:

在xml中:

<ImageButton
    android:id="@+id/b_checkEv" 
    android:src="@drawable/img_huella" 
    ... />

活动中:

     ImageButton ib = (ImageButton) findViewById(R.id.b_checkEv);
     Drawable dr = ib.getDrawble();

我使用 ib.setDrawable() 在代码中动态更改 ImageButton 的图像。 任何人都知道我如何从 Drawable 中获取资源 ID,以便知道每个时刻在 ImageButton 中设置了哪个图像?

谢谢!

【问题讨论】:

  • 您可以只维护一个包含此值的 int。前任。 int currentImage = R.drawable.image; ib.setDrawable(currentImage);

标签: android resources drawable imagebutton


【解决方案1】:

控制 Android 按钮的最佳方式是标签。

您可以在此处执行“ib.setTag("image1.png")”并管理图像数据。

然后你可以执行“String imageName = ib.getTag()”并获取图像名称。

问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    相关资源
    最近更新 更多