クリックしたときに画像ボタンの色合いを変更するコードがあります。
ここにJavaコードがあります
button.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent me)
{
if (me.getAction() == MotionEvent.ACTION_DOWN)
{
button.setColorFilter(Color.argb(150, 155, 155, 155));
}
else if (me.getAction() == MotionEvent.ACTION_UP)
{
button.setColorFilter(Color.argb(0, 155, 155, 155));
}
return false;
}
});
コードはこの xml で正常に動作しており、クリックするとボタンが暗くなります。
<ImageButton
android:id="@+id/schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="138dp"
android:layout_y="169dp"
android:src="@drawable/schedule"
/>
しかし、このxmlでは機能していません。クリックしてもボタンは暗くなりません。
<ImageButton
android:id="@+id/schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="138dp"
android:layout_y="169dp"
android:background="@drawable/schedule"
/>
android:background を使用すると setColorFilter が機能しないのはなぜですか? しかし、私が android:src を使用すると、正常に動作します。