开发者

how do i make different touch and click behaviours for buttons?

开发者 https://www.devze.com 2023-03-16 09:16 出处:网络
Im working on an app with a friend and i want the button to visually press by changing the background and vibrating and then when released it does whatever that button is supposed to do.

Im working on an app with a friend and i want the button to visually press by changing the background and vibrating and then when released it does whatever that button is supposed to do.

the buttons i have right now only have an onclick method but i want it vibrate when touched and execute their function when clicked

i know of the ontouch and onclick methods but i cant seem to use them togetherand have already implemented both onclicklistener and开发者_开发百科 ontouchlistener

how might i manage this.


You could do this by only using the OnTouchListener:

@Override
public boolean onTouch(View v, MotionEvent event) {

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        /* Change your button background and vibrate */
    }
    else if (event.getAction() == MotionEvent.ACTION_UP) {
        /* Button's functionality */
    }

    return true;
}  

Hope it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消