我试图比较两个drawable,但没有成功。我做了一些研究,甚至有一个类似的问题,但没有帮助。
在我的应用程序中,我使用getCompoundDrawablesWithIntrinsicBounds
来获取EditText中ImageView的正确位置。然后我需要检查哪个图像资源被分配在那里。
这个小样本应该可以工作,不是吗?尽管如此,它返回“不相等”。
Drawable drawable1 = ContextCompat.getDrawable(getApplicationContext(),R.drawable.cor);
Drawable drawable2 = ContextCompat.getDrawable(getApplicationContext(),R.drawable.cor);
if(drawable1 == drawable2){
System.out.println("equal");
}else{
System.out.println("not equal");
}