Search Unity

Status Bar Always Hidden on Android

Discussion in 'Android' started by lloydg, Oct 22, 2015.

  1. davidosullivan

    davidosullivan

    Joined:
    Jun 9, 2015
    Posts:
    385
    I need this too...

    I had build errors with the github code because '@String/app_name' needed to be '@String/app_name' for me...

    Also is there anyway to have it not transparent- i.e. that the Unity part just goes up as far as the bottom of the status bar?
     
  2. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    @Carappene If I remember correctly, to hide the navigation bar - you need to enable the immersive fullscreen mode https://developer.android.com/training/system-ui/immersive.html

    However, for Unity apps, showing the status bar (on top) requires you to show the navigation bar (on the bottom). No idea how you managed to get the "noAndroidBar" screenshot o_O Maybe it's device specific.

    As for the UI and the bar "eating" your content - you have to design the UI so that it automatically fills/stretches/shrinks depending on the screen size, using anchors or something like that - I'm not an expert here.

    As for the status bar color - I think you can configure it in Android themes/styles.
     
  3. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    @davidosullivan
    1. Full error message would be helpful (copy it from Unity console details)
    2. From the docs:

    1. If you don't want the status and navigation bars to be translucent, change the theme in manifest from UnityTransparentStatusBarTheme to UnityStatusBarTheme

    This will make the satus bar opaque, and Unity will not render behind it.
     
  4. Anne-Pier

    Anne-Pier

    Joined:
    Sep 22, 2017
    Posts:
    7
    @Yury-Habets
    I saw in your first reply to this post a few years back, you are using an ActionBar in the screenshot. I'm currently trying to get an ActionBar in my Unity project but I'm having problems with it and wondering if it's possible without having to export my project to Android Studio.

    I'm not 100% sure if you were using an ActionBar but it sure looked like it, if this is the case could you give me a lead as to how I can achieve this. I don't know if that was actually your ActionBar either, if it wasn't and haven't done it, could you at least tell me whether it is possible to get this in Unity.

    Thanks a lot :)
     
  5. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    @Anne-Pier this is a screenshot from the Internets, not an actual app (made with Unity) I was running.
    Sorry not much I can offer you here. https://developer.android.com/reference/android/app/ActionBar.html and https://developer.android.com/training/appbar/index.html provide some insight, but you'd definitely need to tweak the Activity and probably the manifest - set the necessary flags etc.

    You could start with the plugin https://github.com/Over17/UnityShowAndroidStatusBar and extend the activity there.
     
  6. Anne-Pier

    Anne-Pier

    Joined:
    Sep 22, 2017
    Posts:
    7
    @Yury-Habets I followed the developer links, sadly I am getting the error ''You need to use a Theme.AppCompat theme (or descendant) with this activity." I am already doing this, checked it like 50 times just to make sure. I'm unsure if AppCompatActivity can work with Unity. If you have any knowledge about this then I'd love to hear it.

    I'll take a look at your plugin and see what I can do.
     
  7. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    For the Theme.AppCompat and AppCompatActivity, you'd need this library https://developer.android.com/topic/libraries/support-library/index.html and quite some manual work to make it up and running.

    You could easily use the normal Activity instead of AppCompat, plus normal Theme instead of AppCompat, in a simple Unity application. Most Google samples are using the support library because it allows you to use latest features in your code and don't care about the feature not supported by an older phone. Moreover, using AppCompat is recommended by Google. We don't use it in Unity mostly because of the size considerations (it's huge).

    Bottom line - looks like you have two ways:
    - either modify samples from google and use normal classes instead of the classes from support library (appcompat)
    - or try adding appcompat to your project, and modify the manifest to make use of the appcompat features.

    Sorry I'm not giving very specific steps to follow because I have no idea about your actual use case - it's up for you to decide. And you definitely need some basic Android dev knowledge to tackle it.
     
  8. Anne-Pier

    Anne-Pier

    Joined:
    Sep 22, 2017
    Posts:
    7
    @Yury-Habets Yeah I figured I could do the same thing with normal Activity, when following the Android Developer Guide it said to extend AppCompatActivity which is why I did it. Normal Activity works fine and I got most of the things going.

    I have 1 final question, when building UI in Android Studio and calling the Activity in Unity, for some reason all buttons I created in Android Studio go back to 0,0. I've set the constraintlayout on them it just doesn't seem to work. Any suggestions on why this could happen? When I did the same thing in an Android Studio app and build it, it did work but once I get it to Unity it doesn't. Not getting any errors either but maybe I have to do something for it to work I have no idea.

    Thanks in advance and thanks for all your input!
     
  9. Anne-Pier

    Anne-Pier

    Joined:
    Sep 22, 2017
    Posts:
    7
    Solved that myself actually by using RelativeLayout instead of ConstraintLayout.
     
    Yury-Habets likes this.
  10. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    313
    Does someone know how to change status bar style using provided abode Git repo solution?
     
  11. cmbellman

    cmbellman

    Joined:
    Sep 19, 2013
    Posts:
    20
    @Yury-Habets, On my Note 8 using this plugin and fullScreen = false, I either can choose to have the navigation bar to automatically hide (which will work for the unity android build) or always show the navigation bar. The latter will not work because the navigation bar is displayed semi transparent above the app (as does the status bar) and the UI i have in the bottom can not be touched since the navigation bar covers it. Screen.safeArea does not seem to consider statusbar or navigationbar when I use the plugin.

    Do you have any suggestion on how to handle this? I really need to show statusbar in my game.
     
  12. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    @cmbellman Maybe it has to do with the Transparent theme used by default?
     
  13. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    @novaVision you may want to modify the theme in supplied AndroidManifest.xml. If you want to create and use your own theme - you need to add it to res/values/.
     
  14. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    313
    iOS got great methods to switch from dark to light theme, with/without background. I tried to find solution to do the same but didn't find a way to change icons/symbols colors from white to black + make background transparent..
     
  15. Allasstar

    Allasstar

    Joined:
    Aug 1, 2013
    Posts:
    12
    How change status bar background color to white and info(text,clock, batery, etc...) to black? what file need to be edited and where is it located?
     
  16. Sam_Wong

    Sam_Wong

    Joined:
    Jan 13, 2018
    Posts:
    1
    Hi,

    Sorry if this has been asked before but I am really having difficulties implementing this plugin as I just started using unity.
    Can someone who have successfully implemented this plugin enlighten me what are the proper steps to take.

    Currently, I have placed the plugin folder under Assets.
    As for the src/UnityShowAndroidStatusBar, I placed it along side with where the Assets folder is located. But I'm not sure if this is where it should be placed.

    For the build instructions, I found the classes.jar under the TEMP folder but I'm no sure what to do with it.
    As for the gradlew assemble, I can't seem to find it.
    Sorry if I interpreted the instructions incorrectly, please feel free to correct me

    Thank you
     
  17. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    484
    Check the manual about using android plugins https://docs.unity3d.com/Manual/PluginsForAndroid.html
     
  18. Rafael_CS

    Rafael_CS

    Joined:
    Sep 16, 2013
    Posts:
    96
    i think the plugin dont work in galaxy s8 and unity 2017.3 ;(...
    i created a clean project, added the plugin and created a gameobject that sets Screen.fullscreen = false.

    the bar seems to appear and disappear (unity reverted to full screen mode?) and it is always setted to fullscreen in splashscreen
     
    Last edited: Mar 10, 2018
  19. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
  20. fafase

    fafase

    Joined:
    Jul 3, 2012
    Posts:
    156
    Last edited: Apr 1, 2018
  21. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    No repro - works fine for me on a S8.

    The "flickering" of going to fullscreen and back is, unfortunately, expected - we use fullscreen for the splash screen. However, an option to disable fullscreen for the splash screen is coming. Stay tuned!
     
  22. aCallum

    aCallum

    Joined:
    Oct 8, 2012
    Posts:
    5
    Very interested to hear more about this upcoming non-fullscreen option. Got any more information yet?
     
    phobos2077 likes this.
  23. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
  24. Mario020

    Mario020

    Joined:
    Jun 20, 2017
    Posts:
    24
    I am at the point 'Extend the UnityPlayerActivity.' from the docs https://docs.unity3d.com/Manual/AndroidUnityPlayerActivity.html
    Now I get 6 errors with the OverrideExample.java: package does not exist for android.os,util,activity and bundle.
    This is the command I am trying to, which I had to find somewhere else because the doc above is not particularly detailed about this (not even referring to additional information), which is an understatement.
    javac /Applications/Unity/PlaybackEngines/AndroidPlayer/Source/com/unity3d/player/OverrideExample.java -classpath /Applications/Unity/PlaybackEngines/AndroidPlayer/Variations/mono/Development/Classes/classes.jar
     
  25. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    You need to path android.jar as part of the classpath/bootclasspath to make it compile.
    android-sdk/platforms/android-16/android.jar, for example
     
  26. Mario020

    Mario020

    Joined:
    Jun 20, 2017
    Posts:
    24
    Yuri, Sorry for my late response. It is working now, thank you! Don't know really what I did that made it work. I forgot about the former post with the extending of the UnityPlayerActivity which seems it wasn't neccessary for the statusbar. I followed the instructions from https://github.com/Over17/UnityShowAndroidStatusBar 'How to Build', don't know really what 'gradlew assemble' did. It seemed copying the plugin and adjusting the manifest file was enough?
     
  27. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    Yes you just need to copy the plugin and the manifest, as it's mentioned in the README. "Building" section is for those who want to modify the plugin code and build it again, you don't need it normally.
     
  28. Mario020

    Mario020

    Joined:
    Jun 20, 2017
    Posts:
    24
    I see now, that's easy to implement then. Great, thanks again!
     
  29. Tuni

    Tuni

    Joined:
    May 24, 2013
    Posts:
    74
    I can't get the plugin to work, even with an empty project with one scene and the script which disable the fullscreen. Has anyone an idea what is wrong?

    Edit: Should be fixed in Unity 2018.1.
     
    Last edited: Jun 4, 2018
  30. mansiva2000

    mansiva2000

    Joined:
    Jul 2, 2013
    Posts:
    9
    For anyone else running into issues with the plugin, make sure you use the latest version of Unity. I was having issues getting the status bar to display using Unity 2018.1.0, but after upgrading to 2018.1.5 it works fine.
     
    Yury-Habets likes this.
  31. Krishna_psk

    Krishna_psk

    Joined:
    Feb 2, 2018
    Posts:
    6
    Hi all,

    I have a situation where i need to switch scenes.
    scene 1 is the regular application (for which I should be able to use the plugin - as fellow developers are able to use it)
    scene 2 will be a VR scene

    my query - is it possible to disable the 'status bar' when navigating to the VR scene??
    basically a toggle between showing 'status bar' & not showing the 'status bar' when using the non-VR & VR scenes??

    I have this doubt as i'm very new to using the manifest files..
     
  32. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    Yes that would be hard.
    You can probably set the necessary styles programmatically instead of using the manifest, but something might not work afterwards. Unfortunately I don't have the code at hand; we used to have it in Unity some time but then switched to manifest/themes, and the issues were gone.
     
  33. Krishna_psk

    Krishna_psk

    Joined:
    Feb 2, 2018
    Posts:
    6
    @Yury-Habets thank you for your response.. I think it is better i omit the part ;);)
    Unavailability of an option is far better than having something which has no guarantee on the stability..
     
  34. PabloC3

    PabloC3

    Joined:
    Oct 3, 2018
    Posts:
    1
    Hi everybody!

    We're using the Status plugin on our app, and we noticed this forced it to enable the navigation bar, meddling with the UI. The thing is, some devices don't have the navigation bar and those uses the buttons or some gadget bundled with it. Is there a way to detect which devices have the navigation bar by software?

    Thanks in advance!

    EDIT: Nevermind, we fixed it. Changing the theme on AndroidManifest made it work.
     
    Last edited: Oct 22, 2018
    carpetres and Yury-Habets like this.
  35. Carappene

    Carappene

    Joined:
    Aug 24, 2017
    Posts:
    3
    I cannot understand how it is not added to Unity. Unity added the Android Permission Runtime on 2018.3, and I'm literally amazed that there is no integrated way to control the status bar. Relying on this plugin, that takes over the main activity, it's not definetelly the way... I know you removed it because it caused unexpected behavior, but this needs to be added...
     
    softone likes this.
  36. prawn-star

    prawn-star

    Joined:
    Nov 21, 2012
    Posts:
    40
    Hi
    So is it possible to have full screen mode that hides the soft-key navigation keys but shows the status bar.
    It seems odd that on some devices, navigation keys have been moved to the screen to have a larger screen area, but you can't use that area of the screen for UI as the navigation bar will block any UI you put there
     
    Last edited: Dec 3, 2018
  37. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    113
    @Yury-Habets I believe I've found an incompatibility issue with Android API 28 (PIE). Also, this post contain information on how to change colors to the navigation/status bar, that many have asked.

    First of all, I've downloaded "UnityShowAndroidStatusBar" from github and opened the src project in Android Studio.

    Made a simple modification to styles.xml for v21 to change the color of the status and navigation bar:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <style name="UnityStatusBarTheme" parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
    <item name="android:colorPrimaryDark">#03A9F4</item>
    <item name="android:navigationBarColor">#4CAF50</item>
    </style>
    <style name="UnityTransparentStatusBarTheme" parent="UnityStatusBarTheme">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    </style>
    </resources>


    As you can see by just adding those two lines, you can define both colors. Generated an arr file and used it in a test project, as if it was the provided arr on the github project and success! It works.

    Also I edited the manifest.xml as indicated in the GitHub page, to use non-trasparent bars (by changing
    UnityTransparentStatusBarTheme to UnityStatusBarTheme)

    Here you can see different results in diferent api versions. This have been tested using the Android emulator using a "Pixel 5x" configuration and several Android versions:

    API 19 (KitKat): Because custom colors to the bars isn't available they appear in black as expected. No problem changing orientation, it all works.
    Api 19 Portrait.png Api 19 Landscape.png

    API 21 (Lollipop): Here we start to see some color, since it's the first version to support this feature. It works like before but more colorful, just as we wanted. BUT once we go landscape... black navigation bar! That's no good... but that's because color can't be set on landscape using Lollipop
    Api 21 Portrait.png Api 21 Landscape.png

    <continues in next post, due to image limit>
     
  38. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    113
    API 26 (Oreo): No problems here! Everything looks and works as expected. Yay!
    Api 26 Portrait.png Api 26 Landscape.png

    API 28 (Pie): Ok, here comes trouble... At first it loads ok and looks nice...
    Api 28 Started Vertical 1.png

    But as soon as we rotate... DISASTER!
    Api 28 Started Vertical 2.png

    As you can see there's a weird bar at the bottom of the screen. And the navigation bar is white. So now we kind of have TWO navigation bars. But the worst part is that if you go back to landscape...
    Api 28 Started Vertical 3.png
    ... it's even more broken, with a "fake" trasparent bar.

    This also happens when starting the app in landscape. It looks ok, but as soon as you change orientation, the "fake bar" appears... @Yury-Habets any idea what could be the problem?
     
  39. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    Looks bad...
    Could you open an issue on github, mention the Unity version, your device model and attach the project?
    Thank you!
     
    SVC-Games likes this.
  40. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    113
  41. unity_xrPBQ-2zcfd-DA

    unity_xrPBQ-2zcfd-DA

    Joined:
    Jun 15, 2018
    Posts:
    19
    Hey Yury, I am having a similar issue I have an android app in which an activity integrates unity scene as fragment everything is working fine but when the unity loads i.e the unity splash screen the whole app goes into full-screen mode and then it exits full-screen mode as in one of my script that is attached in the scene I called Screen.fullScreen=false.

    I don't want my app to go in full-screen mode when the unity is loading is there any solution for this?

    I guess the issue is what you explained that it is because of unity internal settings. And I also read in your reply that 2018.3 has something which will allow unity to open in non-fullscreen mode. I am currently using unity 2018.2.2f1. So is upgrading to unity 2018.3 will solve my issue or is there something I could do to solve this issue in the current version I am working in.
     
  42. rjonaitis

    rjonaitis

    Unity Technologies

    Joined:
    Jan 5, 2017
    Posts:
    52
    2018.3 has a player settings option "Start in fullscreen mode", if it's disabled full screen will not be enabled before loading scripts. Not sure if it will solve your issue.
     
  43. unity_xrPBQ-2zcfd-DA

    unity_xrPBQ-2zcfd-DA

    Joined:
    Jun 15, 2018
    Posts:
    19
    Yeah thanks. I have tried that and it did solve my issue in some way like now the app action bar and bottom navigation bar stays but somehow the app will expand to phone status bar area. I don't know if its a bug or if that's how it supposed to work.
    I also have one more issue that is kind of weird to me. I have attached two screenshots of my app one is normal android activity in landscape mode and you can see that action bar covers the full width of the screen.

    And in the second screenshot I have an android activity which has a unity scene fragment with a camera feed and on top right corner you can see the action bar is not expanded fully there's a bit of white space. Action bar does not cover the full width of the screen. If anyone can help me this that would be great.

    And you can also see that also the status bar also disappears in the 2nd screenshot.
     

    Attached Files:

  44. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    113
    Yeah, that's the issue I've reported a few post above. Still no news on that. I've also posted the issue in GitHub but so far, no response: https://github.com/Over17/UnityShowAndroidStatusBar/issues/18

    Have you tried on devices with API 26 or below? There seems to be no issues there, just with devices using API 28 (Pie)
     
  45. unity_xrPBQ-2zcfd-DA

    unity_xrPBQ-2zcfd-DA

    Joined:
    Jun 15, 2018
    Posts:
    19
    Yeah, my device is API 26 (Oreo) only. So I guess its not with API 28 only. I have checked with a couple of device with API 26 all have the same issue.
     
  46. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    271
    @Yury-Habets or anyone else. Is there a way to display the status bar and get the safe area associated to this bar ?
    Cause currently except if I'm doing something wrong the safe area return by unity get rid of this bar add to the activity in not immersive mode.

    It's quite a pain cause our application use this safe area to be rendered but when we display this one, some part of it are behind the status bar whereas it mustn't.

    Is it possible to do the same with the navigation bar and the safe area again ?
     
  47. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    271
    I found a solution on my side, but It's limited to OREO 8.1 cause from what I know the variable I used is not available on older API.
    https://github.com/Over17/UnityShowAndroidStatusBar/issues/19

    For me, it solves the issue with notch device what was the ones that generates this weird bar but I haven't test on a lot of devices sadly :/
     
  48. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,074
    If I understand you correctly:

    If you enable the status bar and the navigation bar, and they are opaque, the Screen resolution returned by Unity will already account for these areas. There is no need to calculate the safe area.

    If you make them transparent, then it's a bit more complicated, and you'd have to calculate the height of the status bar and navigation bar and try to subtract it from Screen.height. Any built-in Unity APIs won't help you with that, unfortunately.
     
  49. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    271
    @Yury-Habets I solve all my issue concerning those bar. But I'm having an issue with notch devices due to rotation from portrait to landscape that result with a display similar to what I have reported on your github
     
    Last edited: Apr 2, 2019
  50. Lex

    Lex

    Joined:
    Dec 2, 2009
    Posts:
    38
    Can I have a transparent status bar and opaque navigation bar with this?

    Edit: Yes we can, just keep the theme as UnityTransparentStatusBarTheme and use the following code for v21.


    Code (Boo):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <resources>
    3. <style name="UnityStatusBarTheme" parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
    4.     <item name="android:colorPrimaryDark">#000000</item>
    5.     <item name="android:navigationBarColor">#000000</item>
    6. </style>
    7. <style name="UnityTransparentStatusBarTheme" parent="UnityStatusBarTheme">
    8.     <item name="android:windowTranslucentStatus">true</item>
    9.     <item name="android:windowTranslucentNavigation">false</item>
    10. </style>
    11. </resources>
    You can even control the color of the navigation bar with the navigationBarColor property.

    Edit2: Actually if you use #000000 for the navigation bar it gets overriden by Android's default color (which in my case was a gray bar), just use #010101 and it work's fine though.
     
    Last edited: May 22, 2019
unityunity