Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Listen to a disabled button

How can I respond to an event based on clicking a disabled Button. I have a requirement that I have to present Dialog, when a disabled Button is clicked but the listener I have assigned does not fire even when I setClickable(false)

Am an android noob, sorry.

like image 242
Justin Avatar asked Sep 06 '25 11:09

Justin


1 Answers

You can for example use #setActivated() method instead. Disabling a view will ignore all events. https://developer.android.com/reference/android/view/View.html#setActivated(boolean). Then you can customize text and background styles with android:state_activate attribute if you need:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="false"
      android:color="@color/a_color" />
    <item android:state_activated="true"
      android:color="@color/another_color" />
</selector>
like image 166
Ricard Avatar answered Sep 07 '25 23:09

Ricard