【发布时间】:2014-10-28 21:31:38
【问题描述】:
我为 ImageButton 编写 onClick 方法,我必须将按钮中的图像与资源文件夹中的另一个图像进行比较才能做一些事情。 这是我写的代码,我放了一些日志消息:
public void onClick(View v){
Log.e(LOGTAG, "bolarojo: "+getResources().getDrawable(R.drawable.bolarojo).getConstantState().toString());
Log.e(LOGTAG, "bolaclic: "+v.getBackground().getConstantState().toString());
if(v.getBackground().getConstantState().equals(getResources().getDrawable(R.drawable.bolarojo).getConstantState())){
Log.e(LOGTAG, "buh");
它显示: bolarojo: android.graphics.drawable.BitmapDrawable$BitmapState@4106ac08 bolaclic: android.graphics.drawable.StateListDrawable$StateListState@41070780 由于 v 持有 R.drawable.bolarojo 日志消息不应该相同吗?无论如何,我不明白为什么它不显示“buh”。
【问题讨论】:
标签: android drawable imagebutton