I would like to get the same effect as a "Button" by clicking on an "ImageButton" thanks in advance.
I would like to get the same effect as a "Button" by clicking on an "ImageButton" thanks in advance.
It can be achieved by having images that simulate the effect of the button when it is selected and when it is not, these images are configured in a selector
that your ImageButton
would use:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/img_boton_seleccionado" />
<item android:state_selected="false"
android:drawable="@drawable/img_boton_no_seleccionado" />
</selector>
something similar to this image:
You can use this animation to simulate a click on an image:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha = "1.0"
android:toAlpha = "0.5"
android:duration = "300">
</alpha>
<scale
android:fromXScale = "1"
android:toXScale = "0.9"
android:fromYScale = "1"
android:toYScale = "0.9"
android:pivotX="50%"
android:pivotY="50%"
android:duration = "50">
</scale>
</set>
In the onClick event loads the animation to be able to visualize the effect:
public void onClick(View view) {
view.startAnimation(AnimationUtils.loadAnimation(Context, R.anim.imagen_click));
}