Hello,
I develop an Android game and I need a modeless dialog; a dialog which, when shown on the screen, does not block touch events being sent to area outside the dialog.
Thus I have followed the advice given in
and I have such dialog, except that extensive testing proves that it does not work on some Samsung phones.
Here’s how I initialize my dialog:
import androidx.appcompat.app.AppCompatDialogFragment;
public class MyDialog extends AppCompatDialogFragment
{
@Override
public void onStart()
{
super.onStart();Dialog dialog = getDialog(); if( dialog!=null ) { dialog.setCanceledOnTouchOutside(false); Window window = dialog.getWindow(); if( window!=null ) { window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } } }
I have tested the above on emulators and many real phones. Results:
Works on all emulators, on LG Nexus 5X (Android 8.1) on HTC Desire 12, on several Huawei phones, on all older ( running Android 8.1.0 and below ) Samsung phones. But on new Samsung phones, every single one running Android 9 or 10, the above does not work - if I try to click on a Button that’s outside the Dialog, the Button’s onClick() method never gets called.
It is thus as if the flag FLAG_NOT_TOUCH_MODAL was not working.
Any pointers? Workarounds?