Search Unity

Unity Android Show Status and NavegationBar(must not cover the game screen) and set statusBar color.

Discussion in 'Editor & General Support' started by jos_valentin, Jan 25, 2021.

  1. jos_valentin

    jos_valentin

    Joined:
    Aug 4, 2020
    Posts:
    23
    I need to show the status and navegation bar without losing space on the game screen, and add a Gray color only in status bar. I have tried this code to show the status Bar:
    Code (CSharp):
    1.     private static void setStatusBarValueInThread()
    2.     {
    3.         using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    4.         {
    5.             using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
    6.             {
    7.                 using (var window = activity.Call<AndroidJavaObject>("getWindow"))
    8.                 {
    9.                     window.Call("setFlags", 2048, -1);
    10.                 }
    11.             }
    12.         }
    13.     }
    and y have set : Screen.fullScreen = false; on the Awake() and this works perfectly. The problem comes when i want to change the color, it doesn't change, the status bar is still on black color.
    Code (CSharp):
    1.     private static void applyUIColorsAndroidInThread()
    2.     {
    3.         using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    4.         {
    5.             using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
    6.             {
    7.                 using (var window = activity.Call<AndroidJavaObject>("getWindow"))
    8.                 {
    9.                     window.Call("setStatusBarColor", unchecked((int)_statusBarColor));
    10.                 }
    11.             }
    12.         }
    13.     }
    Both methods are called as JavaRunnables in a code like this:
    Code (CSharp):
    1.          using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    2.         {
    3.             using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
    4.             {
    5.                 activity.Call("runOnUiThread", new AndroidJavaRunnable(setStatusBarValueInThread));
    6.             }
    7.         }
    Thanks, and i hope someone can help me.