You can override onTouchEvent and create a listener like this :
class MyButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.materialButtonStyle) : MaterialButton(context, attrs, defStyleAttr) {
private var onDisableClickListener: OnClickListener? = null
override fun onTouchEvent(event: MotionEvent?): Boolean {
if (!isEnabled && event?.action == MotionEvent.ACTION_DOWN) {
onDisableClickListener?.onClick(this)
}
return super.onTouchEvent(event)
}
fun setOnDisableClickListener(l: OnClickListener?) {
onDisableClickListener = l
}
}
In your activity :
button.setOnDisableClickListener {
Toast.makeText(this), "The button is disabled", Toast.LENGTH_SHORT).show()
}
button.setOnClickListener {
Toast.makeText(this), "The button is enabled", Toast.LENGTH_SHORT).show()
}