Hiding the System UI on Lollipop Hiding the System UI on Lollipop android android

Hiding the System UI on Lollipop


If the device is rooted you could disable the systemui pm disable-user com.android.systemui and then the device-owner method works fine.

This method should not be used if the device runs other apps, because if your app crashes the systemui might be disabled and the user can't interact with the device.

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>&device-owner package="com.mycompany" name="*mycompany" />


I have used set following setup to get rid of System UI in Android Marshmallow

final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION        | View.SYSTEM_UI_FLAG_FULLSCREEN        | View.SYSTEM_UI_FLAG_IMMERSIVE;

and OnCreate i have

this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_instructions);getWindow().getDecorView().setSystemUiVisibility(flags);getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

Then i have added code to hide back key if user swipes top or bottom screen.

/* Hides Navigation bar again if user swipes it visible */@Overrideprotected void onResume() {        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(                new View.OnSystemUiVisibilityChangeListener() {                    @Override                    public void onSystemUiVisibilityChange(int visibility) {                    getWindow().getDecorView().setSystemUiVisibility(flags);                    }                });    super.onResume();    Log.i(TAG,"Activity Life Cycle : onResume : MainActivity Resumed");}

This will show back key briefly in screen and hides it back.Only problem in this is that if you open new Activity on top of Pinned activity. It doesn't get any onResume indications.


I was having the same issue. This code will work for 4.4 and Lollipop (Tested). Should work on other versions too.

 /**     * Uses Root access to enable and disable SystemUI.     * @param enabled Decide whether to enable or disable.     */    public void setSystemUIEnabled(boolean enabled){        try {            Process p = Runtime.getRuntime().exec("su");            DataOutputStream os = new DataOutputStream(p.getOutputStream());            os.writeBytes("pm " + (enabled ? "enable" : "disable")                    + " com.android.systemui\n");            os.writeBytes("exit\n");            os.flush();        } catch (IOException e) {            e.printStackTrace();        }    }

Of course it requires root