user1659006
user1659006

Reputation: 373

How to disable naviagation bar in Android LockScreen App like CM locker and OS8 lock screen

I tried setting systemUIView(View.GONE) and use Immersive Full-Screen Mode. But users can always get the naviagtion bar back by touching the bottom of the screen. The apps i mentioned above are able to hide it without root or setting default launcher.

Upvotes: 0

Views: 6221

Answers (2)

user1659006
user1659006

Reputation: 373

Okay, I found a solution finally and here is how it's done:

  1. Use SYSTEM_UI_FLAG_IMMERSIVE_STICKY to hide the navigation bar as follow, you may put the code inside onResume of your activity

    View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; decorView.setSystemUiVisibility(uiOptions);

  2. Then, add a system error window using WindowManger and overlay it on top of everything

you can put this unescapable view anywhere you like, but if you want to do it while users locked the screen, add this flag:

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

Et voilà

Upvotes: 2

WannaGetHigh
WannaGetHigh

Reputation: 3924

Well I've never achieved this but it seems that you will need to set some other flags to get this kind of view :

When you use the SYSTEM_UI_FLAG_IMMERSIVE flag, it hides the system bars based on what other UI flags you have set (SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_FULLSCREEN, or both). When the user swipes inward in a system bars region, the system bars reappear and remain visible.

Here is a snippet that you can use to set these flags :

// This snippet hides the system bars.
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    mDecorView.setSystemUiVisibility(
            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 // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

For more information go check Using Immersive Full-screen Mode from the android developer website.

Hope this help.

Upvotes: 0

Related Questions