現在の画像ファイルを確認して、ボタンの背景画像を変更する方法。現在どの画像がオンになっているかを確認して、サウンドのオン/オフの画像を試したいとします。
main.xml
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:onClick="onClickSound"
android:background="@drawable/sound11"
android:onClick="onClickSound" />
main.java
public void onClickSound(View view) {
final Button btn1 = (Button) findViewById(R.id.button3);
Drawable i = btn1.getBackground();
/*How to check which image resource is set*/
btn1.setBackgroundResource(R.drawable.sound00);
}
plzがそれをチェックするのを助けることができますか?試してみましたが、R.drawable.sound00 と "i" を比較できません。