As the title mentioned, I start using this setAllowClickWhenDisabled in order to fulfill my own development requirement: which is able to click on a disabled view, to open up another activity
Requirement: The disabled/grayed out view should be tappable in order to proceed with next activity
This is the clicklistener I put inside the onCreateView
private fun setupStatusClickListeners() {
Log.i(TAG, "setupStatusClickListeners: ")
binding.myStatusToggle()?.apply {
setOnReadOnlySwitchClickListener(object : OnReadOnlySwitchClickListener {
override fun onReadOnlySwitchClick(p0: View?) {
openUnitStatusActivity()
}
}
This is my onCreateView, as I set the setAllowClickWhenDisabled
to true before setup the clicklisteners
fun onCreateView(fragment: CcLoginDetailsFragment) {
if (!FeatureProvider.Feature.COMMAND_CENTRAL_LOGIN.supported) {
return
}
commandCentralLoginPresenter.onViewCreated(fragment)
viewModel.setupBanner(activity.application)
binding.myStatusProgress()?.visibility = View.GONE
binding.unitId()?.visibility = View.GONE
binding.myStatusToggle()?.visibility = View.GONE
binding.unitIdOtherDetails()?.visibility = View.GONE
binding.myStatusToggle()?.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Log.i(TAG, "setupStatusClickListeners2: ")
binding.myStatusToggle()?.setAllowClickWhenDisabled(true)
}
}
setupStatusClickListeners()
}
and this is where the view getting disabled/grayed out, after some flag checking, came into this method and I'm making the isEnabled = false
if (viewModel.isSecondaryStatusSupported.value) {
//some stuff
binding.myStatusToggle()?.visibility = View.VISIBLE
binding.myStatusProgress()?.visibility = View.GONE
binding.myStatusToggle()?.isEnabled = false
//other stuff
}
This is my xml for this custom view
< com.motorolasolutions.uiframework.ReadOnlySwitchView
android:id="@+id/viewStatusOnDutyToggle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:auto_toggle="false"
app:text_primary="@string/title_my_status"
app:text_secondary="@string/status_off_duty" />
I already set the setAllowClickWhenDisabled to true but I still unable to click on it (the disabled view) to open up another activity
This attribute is introduced in API31, my app is 33 as you can see, I wrap it with SDK checking over there
According to the description, it should work but the reality is totally opposite result
I wonder what could be wrong? or is that some overlapping view happening?
It looks like youre facing an issue with the setAllowClickWhenDisabled
functionality in your Android code. Without seeing the complete code and knowing more details about your implementation, its challenging to provide a specific solution. However, I can offer some general suggestions and things to check:
Check Documentation or Source Code:
Ensure that you are using the setAllowClickWhenDisabled
method correctly. Refer to the documentation or source code of the library or view you are using to confirm its usage.
View Hierarchy:
Verify that the view you are trying to click is indeed disabled. You mentioned setting isEnabled = false
. Double-check that this property is correctly affecting the views state.
Order of Operations:
Ensure that you are setting setAllowClickWhenDisabled(true)
before applying the click listeners. The order of operations may affect the behavior.
Click Listener Implementation:
Examine the implementation of your click listener (OnReadOnlySwitchClickListener
). Confirm that it is being triggered and executed correctly.
Logging: Use additional logging statements to trace the flow of execution. Log messages at key points in your code, especially within the click listener, to understand where the issue might be occurring.
View State Changes:
Check if there are other parts of your code that might be changing the view state after youve set setAllowClickWhenDisabled(true)
.
Compatibility Issues: Verify that the library or view you are using is compatible with the Android version you are targeting.
Testing on Different Devices/Emulators: Test your code on different devices or emulators to see if the issue is specific to a particular environment.
If the issue persists after checking these aspects, providing more code or specific error messages would be helpful for further assistance.