How to achieve in android something like on_hover in css ? I want to images in buttons be more light when touch. I have those lightier images but I don't know where to save them.
Asked
Active
Viewed 195 times
2 Answers
1
You could look at the onTouchListener
You will get something like this:
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent == MotionEvent.ACTION_HOVER_MOVE){
//change image
return true;
}
else {
return false;
}
}
Just take a look at the documentation here
Jordy Langen
- 3,551
- 4
- 22
- 32
1
use this below selector.xml and put your image in your drawable folder. call your button background as android:background="@drawable/selector".
<item android:state_pressed="true"
android:drawable="@drawable/darkimage" >
</item>
<item android:state_focused="true"
android:drawable="@drawable/darkimage" >
</item>
<item android:drawable="@drawable/lighterimage" >
</item>
Padma Kumar
- 20,710
- 17
- 71
- 129