I am creating an android app and I want to have an ImageButton
change to a pressed sprite I created when it is pressed and then when it is uppressed to change back to the original sprite.
I tried messing with the .isPressed()
function but it is unlike the event
function and so it doesn't work the same like ACTION_DOWN
, it mostly froze the program and occasionally did something but not what it should.
Can anyone help?
XML:
<ImageButton
android:id="@+id/player_down"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#00000000"
android:scaleType="centerInside"
app:srcCompat="@drawable/player_down_1"
MainActivity:
public void onClick(View view) {
if (view == player_down) {
pixelGridView.player_goDown();
}
MainActivity with the filed try:
if (view == player_down) {
player_down.setImageResource(R.drawable.player_down_2);
if(!player_down.isPressed()) {
player_down.setImageResource(R.drawable.player_down_1);
pixelGridView.player_goDown();
}
}