如果可绘制对象为A,如何获取图像按钮的可绘制对象进行比较,我该如何做呢?非常感谢。
switch(getDrawableId(buttonRepeat)) {
case R.drawable.a:
mediaPlayer.setLooping(true);
break;
case R.drawable.b:
mediaPlayer.setLooping(false);
break;
default:
break;
}
getDrawable()
在ImageButton中使用方法并使用进行比较.getConstantState().equals()
样例代码:
ImageButton btn = (ImageButton) findViewById(R.id.myImageBtn);
Drawable drawable = btn.getDrawable();
if (drawable.getConstantState().equals(getResources().getDrawable(R.drawable.myDrawable).getConstantState())){
//Do your work here
}
参考文献:
http://developer.android.com/reference/android/widget/ImageButton.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句