繁体   English   中英

如何获取赋予ImageView的可绘制对象的资源ID

[英]How to get the resource id of a drawable given to an ImageView

我需要获取我通过xml分配给ImageView的可绘制对象的ID。

我有不同的按钮需要在按下时改变外观,因此我只想为所有这些按钮编写一个方法,即可将NOT_TOUCHED可绘制ID和TOUCHED可绘制ID放入2个数组中,依此类推...

我怎样才能做到这一点?

如果要在触摸或不触摸图像时将图像视图更改为其他状态,则最好使用可绘制的选择器资源。 创建如下的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM