Skip to content Skip to sidebar Skip to footer

Custom View Not Responding To Touches

I've created a custom view which should change it's background image when pressed, highlighted or disabled. The app runs but the button doesn't change it's background. here's my co

Solution 1:

It extends from View, not button, so it's not clickable or focusable by default. Adjust with

android:clickable="true"android:focusable="true"

in your XML.

You can also set these in the constructor of your View class if you want to do it in java:

setFocusable(true);
setClickable(true);

Solution 2:

in my case I was using a custom view with a constraint layout as the root .and I was not getting click events on setOnClickListener of my custom view,it turns out that I needed to set android:clickable="false" in the root of my xml for the custom view.apparently , the click event is dispatched to the root of my custom view xml rather than to the custom view it self (i.e setOnClickListener of the custom view )

Post a Comment for "Custom View Not Responding To Touches"