2

I want the app to show only the status bar and have the navigation bar in IMMERSIVE_STICKY mode. Tried a lot of things but somehow the nav bar stays and the status bar is hidden. Can the material theme be messing up with the full screen functionalities?

Tried other related question to the same problem but they address the problem in forms of hacks and also the API is version is older for the solutions. Here is my theme attribute and related setup code:

<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">

        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>```
CodeWithVikas
  • 1,105
  • 9
  • 33
Vishal
  • 391
  • 5
  • 20
  • `windowFullscreen` hides the status bar while the `NoActionBar` theme should hide the system ActionBar even without an explicit `windowActionBar = false`. Could you check if the layout is adding a custom Toolbar as the ActionBar? – shriakhilc Jun 14 '19 at 11:09
  • Tried getting the supportActionBar, the result is null. – Vishal Jun 14 '19 at 11:19
  • When you say 'navigation bar' do you mean the system generated on that appears on the bottom with actions like 'Back', 'Home' and 'Recents'? I misread it as nav drawer, so I was focusing on the ActionBar (the one on top, just under the status bar). – shriakhilc Jun 14 '19 at 11:23
  • Yeah. The bottom one – Vishal Jun 14 '19 at 11:26

2 Answers2

2

According to the docs here, you need to use SYSTEM_UI_FLAG_HIDE_NAVIGATION in order to hide the bottom nav bar. They also pass the SYSTEM_UI_FLAG_FULLSCREEN flag since it is good practice to also hide the status bar when the nav bar is hidden.

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

If I interpreted the question correctly, your requirement is NOT to hide the status bar, and hiding the nav bar. So, you should not be passing the fullscreen flag anywhere. Remove it from the above snippet, and also remove android:windowFullscreen from your theme. This should make the status bar appear as usual.

So your actual uiOptions would be

int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

Note: As mentioned in the docs, IMMERSIVE_STICKY only ensures that any touch event/gesture in the nav bar region is also transmitted to the app. It will still display a translucent nav bar if the user swipes there. As mentioned in other answers, it should be impossible to completely get it removed without some form of root access.


Edit: I initially tested this with AppCompatActivity and the default Theme.AppCompat.Light.NoActionBar theme. Also tested out with OP's android:Theme.Material.Light.NoActionBar (which requires use of Activity instead of AppCompatActivity). Both of them worked.

shriakhilc
  • 2,922
  • 2
  • 12
  • 17
  • I am assuming your API level is definitely above Android 4.1, since that was quite a while ago. – shriakhilc Jun 14 '19 at 11:35
  • Tried it. But it is not working. I mean if I use FULLSCREEN flag then it goes into the IMMERSIVE mode but without it, the navigation bar is visible. – Vishal Jun 14 '19 at 11:42
  • And yeah, I don't want to hide it permanently. Basically, I want the IMMERSIVE behavior but display the status bar. – Vishal Jun 14 '19 at 11:45
  • Could you mention your min API level? Because I made a demo app with this and it works as you want it to. Immersive like nav bar, always visible status bar. Try making a new app yourself and see if it works? That would mean something else in your current application is messing with it. – shriakhilc Jun 14 '19 at 11:51
  • ```minSdkVersion 21``` Yeah. Could be something that I added. I am using a few third-party libraries. – Vishal Jun 14 '19 at 11:53
  • It is working on a new project. Accepting your answer. Will try to find what did I do wrong. – Vishal Jun 14 '19 at 11:57
  • Is the new project using the same Material theme? I just noticed I was using the default theme and not the one you've specified. – shriakhilc Jun 14 '19 at 11:58
  • Nope. The stock one – Vishal Jun 14 '19 at 11:58
  • 1
    Works fine with Material theme and extending FragmentActivity in a new app. Guess I'm messing something up. – Vishal Jun 14 '19 at 12:11
1

1)Through the code, you can hide the action bar using below way.

class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.main_activity)
    supportActionBar?.hide()
  }
}

This line supportActionBar?.hide() hide action bar only.see the attached image.

enter image description here

2)Through the XML with theme

First, add a style in the styles.xml:

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

AndroidManifest.xml and apply it to the activity you want to hide the action bar.

<activity
android:name=".MyActivity"
android:theme="@style/AppTheme.NoActionBar"/>
Sanjay Bhalani
  • 2,424
  • 18
  • 44
  • I wanted to show the status bar and hide the navigation bar. Your code hides the action bar. Irrelevant to the question. – Vishal Jun 14 '19 at 11:22