0

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.

Damir
  • 51,611
  • 92
  • 240
  • 358
  • http://stackoverflow.com/questions/4755871/how-to-set-image-button-backgroundimage-for-different-state/4755934#4755934 – ingsaurabh Nov 01 '11 at 08:25

2 Answers2

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