title: Android 5.0, prevent status bar expansion
body: <p>This is a very old problem, but after making so much effort, I still cannot figure out a possible solution.</p>
  
  <p><strong>The Aim</strong></p>
  
  <p>Actually quite simple. I would like to develop some full screen apps (e.g. games), where the status bar does not expand, however the user touches the screen.</p>
  
  <p>The app should be able to work on Android 5.0, sdk 21 (Lollipop).</p>
  
  <p><strong>What I have done so far</strong></p>
  
  <p>I find <a href="https://stackoverflow.com/questions/25284233/prevent-status-bar-for-appearing-android-modified">this post</a>, which describes how to cover the status bar with a <code>CustomView</code> that absorbs touch events, but it doesn't work for me ...</p>
  
  <p>I even changed the size of the <code>CustomView</code> so that it covers the whole screen, but it still doesn't work, and it cannot even cover my button.</p>
  
  <p>The codes I use are attached below. When run on the device, both the button and the status bar work - nothing is blocked.</p>
  
  <p>Am I missing something?</p>
  
  <p><strong>Codes</strong></p>
  
  <p>In AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:supportsRtl="true"
      android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>In activity_main.xml:</p>
  
  <pre><code>&lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Hello World!"
      android:id="@+id/text_show" /&gt;
  
  &lt;Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Click"
      android:id="@+id/button_click"
      android:onClick="changeText"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true" /&gt;
  </code></pre>
  
  <p>In MainActivity.java:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      WindowManager manager = ((WindowManager) getApplicationContext()
              .getSystemService(Context.WINDOW_SERVICE));
      WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
      localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
      localLayoutParams.gravity = Gravity.TOP;
      localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
              // this is to enable the notification to recieve touch events
              WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
              // Draws over status bar
              WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
      localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
      localLayoutParams.height = (int) (50 * getResources()
              .getDisplayMetrics().scaledDensity);
      localLayoutParams.format = PixelFormat.TRANSPARENT;
      CustomViewGroup view = new CustomViewGroup(this);
      manager.addView(view, localLayoutParams);
      setContentView(R.layout.activity_main);
  }
  boolean key = false;
  public void changeText(View view) {
      TextView tv = (TextView) findViewById(R.id.text_show);
      if (key) {
          tv.setText("hahaha");
      } else {
          tv.setText("eroero");
      }
      key = ! key;
  }
  </code></pre>
  
  <p>In CustomViewGroup (copied from the above link):</p>
  
  <pre><code>public class CustomViewGroup extends ViewGroup {
      public CustomViewGroup(Context context) {
          super(context);
      }
      @Override
      protected void onLayout(boolean changed, int l, int t, int r, int b) {
      }
      @Override
      public boolean onInterceptTouchEvent(MotionEvent ev) {
          Log.v("CustomViewGroup", "**********Intercepted");
          return true;
      }
  }
  </code></pre>