I have a question related to passing touch event f...
# android
s
I have a question related to passing touch event from a dialog fragment to the activity below (parent activity). My goal is to be able to have the dialog showing but allow the transparent section of the dialog to pass touch events back to the parent activity so that other things like clicks/ keyboard input can still happen as the dialog is being shown. Currently i am using
Copy code
dialog?.window?.decorView?.setOnTouchListener { view, motionEvent ->
    activity?.dispatchTouchEvent(motionEvent)
    false
}
to try to dispatch the touch event to the activity but it doesn’t work as i expected. Does anyone have an idea of how to approach this?
z
what's the use case?
s
the use case is a design where two dialogs are shown simultaneously with the possibility to interact with both of them interchangeably (different modes of input the user can make use of)
i
This isn't ever really going to work, unfortunately. It sounds like what you actually want is just an overlaying view (i.e., using a
FrameLayout
with the rest of your activity content below the "dialog") all within the same window.
👍 1
s
follow up…i was able to get it working by setting these flags on the dialog
FLAG_NOT_TOUCH_MODAL,
FLAG_NOT_FOCUSABLE
FLAG_ALT_FOCUSABLE_IM
i
Note that approach is going to break a lot when it comes to screen readers, buttons, etc.
s
yes i can imagine it would break accessibility, how would it affect buttons?
i
Only focusable items get touch events
s
as far as i have been able to test,
FLAG_NOT_TOUCH_MODAL
would capture the events that are within the dialog window, the other flags prevent input focus (keyboard) from being consumed by the dialog (my goal) and also prevent it from drawing over the keyboard
i
Okay, good luck
👍 1