Jyo the Whiff
Jyo the Whiff

Reputation: 839

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) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            View decorView = getWindow().getDecorView();
            // Hide the status bar.
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
            // Remember that you should never show the action bar if the
            // status bar is hidden, so hide that too if necessary.
            ActionBar actionBar = getActionBar();
            actionBar.hide();
        }
    }

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)

Update:

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

Upvotes: 3

Views: 10106

Answers (4)

Jyo the Whiff
Jyo the Whiff

Reputation: 839

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

As commented by @Academy of Programmer; this solution does not work on Android 6 and above.

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) {
            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;
        }
    }

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

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 receive 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);

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 :

//fullscreen
        requestWindowFeature(Window.FEATURE_NO_TITLE);   
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

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... :)

Upvotes: 7

Jithin Sunny
Jithin Sunny

Reputation: 3402

We cannot prevent the status appearing in full screen mode in kitkat or above devices, so try a hack to block the status bar from expanding.

For an idea, put an overlay over status bar and consume all input events. It will prevent the status bar from expanding.

Upvotes: 4

KishuDroid
KishuDroid

Reputation: 5451

Using below code you can use full screen ;

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Write below code above setcontentview.

Note : Don't give any theme to this activity.

Hope this helps.

Upvotes: 2

Sasi Kumar
Sasi Kumar

Reputation: 13348

use following code onCreate

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 requestWindowFeature(Window.FEATURE_NO_TITLE);   
 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
 }

Upvotes: 0

Related Questions