如何获取给予ImageView的drawable的资源ID

时间:2014-12-21 23:49:16

标签: android imageview

我需要获取我通过xml分配给ImageView的drawable的id。

我有不同的按钮需要在按下时改变外观,所以我想只为其中的所有内容编写一个方法,将NOT_TOUCHED可绘制的ID和TOUCHED可绘制的ID放入2个数组中上...

我该怎么做?

1 个答案:

答案 0 :(得分:0)

如果要在图像视图触摸或不触摸时将图像视图更改为其他状态,最好使用可绘制选择器资源。创建一个drawable / background.xml,如下所示,然后设置为图像视图的背景。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/focused_image" android:state_focused="true"></item>
<item android:drawable="@drawable/selected_image" android:state_selected="true"></item>
<item android:drawable="@drawable/normal_image"></item>

</selector>