Ok, I solved my problem by overriding the OnTouch listener.
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean { when (view) { next -> { Log.d("next", "yeyy") when (motionEvent.action){ MotionEvent.ACTION_DOWN -> { val icon: Drawable = ContextCompat.getDrawable(activity.applicationContext, R.drawable.layer_bt_next) icon.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY) next.setImageDrawable(icon) } MotionEvent.ACTION_UP -> { view.performClick() next.setImageResource(R.drawable.layer_bt_next) } } } previous -> { //ingredients here XD } } return true }
And so I can call single onTouch and implement it for many buttons, and also use onClick by:
view.performClick()
Do not forget to implement:
View.OnTouchListener
And set the listener:
next.setOnTouchListener(this) previous.setOnTouchListener(this)
Thank you, Lord! :)
lambda Nov 08 '17 at 3:05 2017-11-08 03:05
source share