My button has 3 states and the representation of each depends on a particular condition. (You can follow this question I've asked earlier to see the screenshots of what states my button has): Different background for a button's states in Kotlin
I want my button to kind of "block" its pressed state if it is not clickable.
My button's states:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/background_stroke_bluish_rounded_corners_2dp"/>
<item android:state_pressed="false"
android:drawable="@drawable/background_bluish_rounded_corners" /> <!-- pressed -->
<item android:state_pressed="true"
android:drawable="@drawable/background_dark_teal_rounded_corners" /> <!-- focused -->
<item android:state_enabled="true" android:drawable="@drawable/background_bluish_rounded_corners"/>
</selector>
How I tried to set the isClickable
to false
:
updateFragmentView?.mFragmentRootView?.btnUpdate?.isClickable = false
Right now it works and the needed event while isClickable = true
doesn't happen, but what I want to implement is not to let the pressed state become visible if the button is not clickable. Is that possible to implement without changing the XML?
Something alike can be found in isUserInteractionEnabled
for iOS. If set to false
, the button's highlighted color doesn't work (if the button has one).
UPD: I've tried setEnabled(false)
and also .isEnabled = true
, but that does influence on the logic of my fragment, so that's not working for me.