Android - Listen to a disabled button Android - Listen to a disabled button android android

Android - Listen to a disabled button


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>


A disabled button cannot listen to any event, but you can customize your own button by extending Button class to make your own definition of disabling


Instead of disabling it, keep it enabled but use a flag to control your "inner state"