ButtonDown and ButtonUp events for Android screen buttons?

yourButton.setOnTouchListener( yourListener );

public boolean onTouch( View yourButton , MotionEvent theMotion ) {
    switch ( theMotion.getAction() ) {
    case MotionEvent.ACTION_DOWN: break;
    case MotionEvent.ACTION_UP: break;
    }
    return true;
}

Kotlin variant

button.setOnTouchListener(object : View.OnTouchListener {
        override fun onTouch(v: View?, event: MotionEvent?): Boolean {
            when (event?.action) {
                MotionEvent.ACTION_DOWN -> {   }
                MotionEvent.ACTION_UP   -> {   }
            }
            return v?.onTouchEvent(event) ?: true
        }
    })

Tags:

Android