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
  • 54,277
  • 94
  • 246
  • 365
  • 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,591
  • 4
  • 23
  • 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
  • 19,893
  • 17
  • 73
  • 130