0

This is not a duplicate question. If it was, I wouldn't ask it. The solution to the supposed duplicate question did not work. So this is not a duplicate question.

I have a fullscreen translucent DialogFragment (a loader fragment) shown over an activity. The activity behind is still receiving touch events. How do you disallow the activity from receiving touch events? I've already set the root layout of DialogFragment to clickable="true", but the activity is still receiving touch events.

Please help.

My DialogFragment code:

public static LoaderDialogFragment newInstance() {
    LoaderDialogFragment df = new LoaderDialogFragment();
    df.setCancelable(false);
    return df;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(STYLE_NO_FRAME | STYLE_NO_TITLE, R.style.AppTheme_LoaderDialog);
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Window w = getDialog().getWindow();
    if(w != null) {
        w.setBackgroundDrawable(new ColorDrawable(Color.parseColor(TRANSLUCENT_COLOR)));
        w.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    }
    return inflater.inflate(R.layout.fragment_loader_dialog, container, false);
}

and layout file:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/loader_dialog_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:indeterminate="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

</android.support.design.widget.CoordinatorLayout>
Poly Bug
  • 1,514
  • 1
  • 14
  • 27
  • 1
    Possible duplicate of [Fragment over another fragment issue](https://stackoverflow.com/questions/10389620/fragment-over-another-fragment-issue) – Reaz Murshed Mar 04 '18 at 12:41
  • @ReazMurshed Thanks for the link, but that didn't solve my problem. I already read that question and tried that solution before posting this. – Poly Bug Mar 04 '18 at 12:57

1 Answers1

1

I've solved my issue.

The STYLE_NO_FRAME is apparently making the dialogFragment view hierarchy disappear.

Removing that, and the activity behind does not receive the touch events anymore.

clickable="true" works for transparent DialogFragment background, but is not necessary for translucent background. I removed it from my layout and the activity still doesn't receive any touch events.

Poly Bug
  • 1,514
  • 1
  • 14
  • 27