3

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

Jyo the Whiff
  • 829
  • 9
  • 23

4 Answers4

7

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

Jyo the Whiff
  • 829
  • 9
  • 23
  • 1
    this is pretty great solution, expecially when you need to show some animation in fullscreen, and after it is done just remove created view. Thank you for providing this code. – DoubleK Jan 15 '16 at 12:05
  • @Jyo the Whiff This is great. Do you know how can i disable the soft keys(Back/Home?Recent App) as well? – Dave Feb 10 '16 at 10:22
  • This solution won't work anymore in the upcoming Android 8 release, when the functionality of WindowManager.LayoutParams.TYPE_SYSTEM_ERROR is gone. See https://www.bleepingcomputer.com/news/security/android-o-will-contain-special-feature-to-fight-off-ransomware/ – Redwolf Jul 07 '17 at 17:54
4

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.

Jithin Sunny
  • 3,352
  • 4
  • 26
  • 42
2

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.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
0

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);
 }
sasikumar
  • 12,540
  • 3
  • 28
  • 48