Custom View not responding to touches

前端 未结 1 1653
别跟我提以往
别跟我提以往 2020-12-11 19:08

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.

相关标签:
1条回答
  • 2020-12-11 19:18

    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);
    
    0 讨论(0)
提交回复
热议问题