I want to hide status bar in my Android application.

I used following:

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                      | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

It works fine below Kitkat. But after upgrading to Kitkat when we swipe finger from top of screen, the status bar appears again as it works as immersive mode.

I don't want this behavior. And the status bar should not appear if finger is swiped from top of screen. How could I achieve this?

2

There are 2 answers

1
Muthukrishnan Suresh On

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

add this in your manifest of the activity.

1
tallpaul On

You cannot permanently hide it. Perhaps consider an overlay that consumes touch events. I have used this:

onCreate()

    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 |
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    localLayoutParams.flags = 0x80000000 | localLayoutParams.flags;
    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height = (int) (25 * getResources().getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;
    LayoutInflater inflater = getLayoutInflater();
    View overlay = inflater.inflate(R.layout.systembar_overlay, null);
    manager.addView(overlay, localLayoutParams);

systembar_overlay.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/ll">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:background="#ff000000"
        android:minHeight="25dp"
        android:longClickable="false">
    </FrameLayout>
</LinearLayout>

This shows a black bar in place of the original. You could make it transparent, or add more widgets to it. You may have to tweak the height to suit your needs.