I am implementing a kiosk mode application and i have successfully made the application full-screen without status bar appearance post 4.3 but unable to hide status bar in 4.3 and 4.4 as status-bar appears when we swipe down at the top of the screen.
I have tried to make it full screen by
Possible duplicate but no concrete solution found
Permanently hide Android Status Bar
Finally the thing i want is, how to hide status bar permanently in an activity?? in android 4.3,4.4,5,6versions
Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.
How do I hide the status bar on Android? With a stock Android phone, press and hold Settings until System Settings appears. Select System UI Tuner > Status Bar, and turn off all the options.
In Android M you have to get an extra permission for making overlays. android.permission.SYSTEM_ALERT_WINDOW
is not enough! So I used the code from the answer of Abhimaan within disableStatusBar()
and had to make an intent to open the right settings dialog. I also added removing view in onDestroy()
in order to enable status bar when the app exits. I also reduced the overlay height to 40 as it seems to be enough. Code works with 5.1 and 6.0 here.
public static final int OVERLAY_PERMISSION_REQ_CODE = 4545; protected CustomViewGroup blockingView = null; @Override protected void onDestroy() { super.onDestroy(); if (blockingView!=null) { WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)); manager.removeView(blockingView); } } @Override protected void onCreate(Bundle savedInstanceState) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this)) { Toast.makeText(this, "Please give my app this permission!", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,Uri.parse("package:" + getPackageName())); startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); } else { disableStatusBar(); } } else { disableStatusBar(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { if (!Settings.canDrawOverlays(this)) { Toast.makeText(this, "User can access system settings without this permission!", Toast.LENGTH_SHORT).show(); } else { disableStatusBar(); } } } protected void disableStatusBar() { 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) (40 * getResources().getDisplayMetrics().scaledDensity); localLayoutParams.format = PixelFormat.TRANSPARENT; blockingView = new CustomViewGroup(this); manager.addView(blockingView, localLayoutParams); }
We could not prevent the status appearing in full screen mode in kitkat devices, so made a hack which still suits the requirement ie block the status bar from expanding.
For that to work, the app was not made full screen. We put a overlay over status bar and consumed all input events. It prevented the status from expanding.
note:
Updated
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
customViewGroup implementation
Code :
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With