title: Android: is there a way to apply android:filterTouchesWhenObscured="true" on every layout?
body: <p>I want to detect and act upon overlays obscuring my App.</p>
  <p>I have the following code to decide what to do:</p>
  <pre><code>final View.OnTouchListener filterTouchListener = new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              if ((event.getFlags() &amp; MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) {
                  Toast.makeText(v.getContext(), &quot;Full overlay detected&quot;, Toast.LENGTH_SHORT).show();
                  return false;
              }
              if ((event.getFlags() &amp; MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED) != 0) {
                  Toast.makeText(v.getContext(), &quot;Partial overlay detected&quot;, Toast.LENGTH_SHORT).show();
                  return false;
              }
              return false;
          }
      };
      view.setOnTouchListener(filterTouchListener);
  </code></pre>
  <p>I tried to apply and inherit the following in onCreate() to apply &quot;filterTouchesWhenObscured&quot; to every Activity:</p>
  <pre><code>View view = findViewById(android.R.id.content).getRootView();
  
  view.setFilterTouchesWhenObscured(true);
  </code></pre>
  <p>But I get different behaviors if I add it via Java or if I add it to the layout;</p>
  <p>The programmatic solution blocks all touch events and does not trigger the OnTouchListener.</p>
  <p>The layout solution allows me to use the OnTouchListener, but needs to be applied to every layout manually.</p>
  <p>Is there a way to get the behavior of android:filterTouchesWhenObscured=&quot;true&quot; without adding it manually to every single layout?</p>