Jyo the Whiff Jyo the Whiff - 1 year ago 260
Android Question

Hide status bar in android 4.4+ or kitkat with Fullscreen

I'm using following code for hiding status bar with full screen purpose:

void HideEverything(){
if (Build.VERSION.SDK_INT < 16) {
} else {
View decorView = getWindow().getDecorView();
// Hide the status bar.
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();

It shows Screen in full-screen mode but when I touch status bar it shows status bar.
I tried other options to add the full screen and no title bar theme in application and activity level in manifest, but still results are the same... :(

I don't want to show status bar at any step.
How to achieve this in android?

Edit :

Android OS version is 4.4.2
(Above code is working on 4.3 but not on 4.4.2)


Problem has been solved...
Answer is written below separately...

Answer Source

No solution could work for the problem as Android version is 4.4.2.

But as per the suggestion by Sunny, problem has been solved by preventing the expansion of status bar.

Solution is:

Write an inline customViewGroup class in your main activity.

public class customViewGroup extends ViewGroup {

        public customViewGroup(Context context) {

        protected void onLayout(boolean changed, int l, int t, int r, int b) {

        public boolean onInterceptTouchEvent(MotionEvent ev) {
            Log.v("customViewGroup", "**********Intercepted");
            return true;

Now in your onCreate method of mainActivity add following code before setContentView() :

WindowManager manager = ((WindowManager) getApplicationContext()

        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 receive touch events
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

                // Draws over status bar

        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = (int) (50 * getResources()
        localLayoutParams.format = PixelFormat.TRANSPARENT;

        customViewGroup view = new customViewGroup(this);

        manager.addView(view, localLayoutParams);

Above code will disable the expansion of status bar. Now make full screen by following code, add it just below the above code and before the setContentView :


Now in manifest add the permission:

<!-- prevent expanding status bar -->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

and you are done.... :)

drawback : This code disables expansion of status bar for the device not just for an activity or an application, so use it if you really need it.

Thank you for all the solutions and suggestions... :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download