Easy way to hide system bar on Android ICS

后端 未结 8 1175
抹茶落季
抹茶落季 2020-11-28 10:32

I will give my ICS tablets for users to complete a survey so I would like the user to work with my app only. They should not be able to switch to the home screen, press back

相关标签:
8条回答
  • 2020-11-28 10:53

    I found a solution that, in my use case, works like a charm by hiding the menu bar even on a NOT ROOTED device:

    setting this flag

    layoutparams.flags = 0x80000000 | layoutparams.flags;
    

    to my window's layout parameters simply does the trick!

    Here's the complete snippet i used:

        Window window = getWindow();
        android.view.WindowManager.LayoutParams layoutparams = window.getAttributes();
        layoutparams.flags = 0x80000000 | layoutparams.flags;
        window.setAttributes(layoutparams);
    

    in my Activity onCreate.

    To find out this I reverse engeneered a non-system Apk I found that was somehow able to do that.

    According to the official documentation:

    http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS

    that "0x80000000" is the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS introduced as a system constant in Api level 21, and it basically indicates that "this Window is responsible for drawing the background for the system bars." and since i'm not manually drawing any system bar, no menu bar is shown.

    I only tested this on a pair of Moverio BT-200 running Android ICS 4.0.3 because that is the device i'm currently working on and also because right now i don't have other device running Api levels prior to 19 under my hands to test it.

    0 讨论(0)
  • 2020-11-28 10:56

    To complement the answers already given, and in case it is useful for someone needing a similar behaviour, there is this tutorial for android devices 4.0 and higher, it tells you how to hide the navigation bar and the status bar (they will reappear when the screen is touched again):

    https://developer.android.com/training/system-ui/navigation.html

    I realize it is not what you need exactly, but might be useful for someone else looking at this problem.

    0 讨论(0)
提交回复
热议问题