获取ImageButton中使用的图像的文件名

时间:2014-04-01 18:06:54

标签: android testing robotium

我正在使用Robotium在Android应用中测试包含ImageButton开关的屏幕。我有两个ImageButtons使用两个PNG图像(on.png和off.png)来显示开关的状态。我正在尝试找到一个方法,它将返回当前显示图像的文件名,以便我可以运行如下测试:

Get the image being displayed by ImageButton1
Verify that the image is "on.png"
Set ImageButton1 to editable state
Select ImageButton1
Get the image being displayed by ImageButton1
Verify that the image is "off.png"

如何在正确的情况下验证ImageButton是否正在显示正确的图像文件?

顺便说一下,图像是在XML元素中设置的。

2 个答案:

答案 0 :(得分:0)

我建议你看看: View.#getDrawableState

应该像:

boolean on = imageButton.getDrawableState()[your.R.id.state_on] == 1;
boolean off = imageButton.getDrawableState()[your.R.id.state_off] == 1;

您还可以查看similar question

答案 1 :(得分:-1)

ImageButton1.getResource().toString();
相关问题