Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt 6.11.0: How to get rid of bar at top
Qt 6.11 is out! See what's new in the release blog

Qt 6.11.0: How to get rid of bar at top

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qt 6.11.0c++javaandroid 16
3 Posts 1 Posters 279 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheoSys
    wrote last edited by
    #1

    Hi,

    my Android app uses the full screen. To be able to use it I'm hiding the bars. Hiding seems to work but with Android 16 a black beam is left on top. The graphics are below this black bar but the key strokes are taken as like the bar doesn't exist. Look at the screen shot. The red frame marks the bar and the blue frame shows the area where it thinks the button is:
    tpanel
    While the program is written in C++, the part to hide the bars is in Java. Here is the code:

    package org.qtproject.theosys;
    
    import android.os.Bundle;
    import android.os.Build;
    import android.app.Activity;
    import android.app.ActionBar;
    import android.view.View;
    import android.view.Window;
    import android.view.WindowInsets;
    import android.view.WindowInsetsController;
    import android.view.WindowManager;
    import androidx.core.view.WindowCompat;
    
    import org.qtproject.theosys.Logger;
    
    public class HideToolbar extends Logger
    {
        static private boolean mBusy = false;
        static private boolean mInit = false;
    
        static public void hide(Activity act, boolean hide)
        {
            if (act == null)
                return;
    
            if (mBusy)
                return;
    
            mBusy = true;
            act.setTheme(R.style.TPanelAppTheme);
    
            act.runOnUiThread(new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        Window window = act.getWindow();
                        View decor = null;
    
                        if (window != null)
                        {
                            WindowInsetsController wic = null; //window.getInsetsController();
    
                            if (wic == null)
                            {
                                decor = window.getDecorView();
    
                                if (decor != null)
                                    wic = decor.getWindowInsetsController();
                            }
    
                            if (wic != null)
                            {
                                if (!mInit)
                                {
                                    wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
                                    WindowCompat.enableEdgeToEdge(window);
                                    mInit = true;
                                }
    
                                if (hide)
                                {
                                    wic.hide(WindowInsets.Type.systemBars());   // All types of bars
                                    log(HLOG_DEBUG, "HideToolbar.hide: Statusbars were hidden.");
                                }
                                else
                                {
                                    wic.show(WindowInsets.Type.systemBars());   // All types of bars
                                    log(HLOG_DEBUG, "HideToolbar.hide: Statusbars were shown.");
                                }
                            }
                            else
                                log(HLOG_WARNING, "HideToolbar.hide: Error retrieving WindowInsetsController!");
                        }
                        else
                            log(HLOG_WARNING, "HideToolbar.hide: Error retrieving window!");
                    }
                    catch (Exception e)
                    {
                        log(HLOG_ERROR, "HideToolbar.hide: " + e);
                    }
                }
            });
    
            mBusy = false;
        }
    }
    
    

    To see the whole program, look at tpanel on Github.
    To initialize the theme I use the following XML:

    <resources>
        <style name="TPanelAppTheme" parent="Theme.AppCompat.NoActionBar">
        </style>
        <style name="TPanelAppTheme.NoActionBar">
            <item name="android:windowActionBar">false</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
        </style>
    </resources>
    

    This worked up to Android 14. Now with edge-to-edge it make troubles. Does anybody has an idea how I can get rid of the black bar?

    A.T.

    T 1 Reply Last reply
    0
    • T TheoSys

      In the mean time I found out how to remove the bars on Android 16. I changed the Java code a little:

                          Window window = act.getWindow();
      
                          if (window != null)
                          {
                              WindowInsetsController wic = window.getInsetsController();
      
                              if (wic != null)
                              {
                                  if (hide)
                                  {
                                      wic.hide(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());   // All types of bars
                                      wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
                                  }
                                  else
                                  {
                                      wic.show(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());   // All types of bars
                                      wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
                                  }
                              }
                          }
      

      The additional parameter WindowInsets.Type.displayCutout() removed the black bars (on a Pixel9 pro they were on the left and on top) but it leaves the task bar visible with transparent background. Buttons under the bar are not clickable. On a Pixel 9Pro it looks currently like this:
      TPanel on Pixel9
      It seems that, if not overwritten by code, Qt honors the notch as well as the bars and places the first pixel (left upper corner) inside the usable space. But it does not correct the hit position. Hitting a button behaves as there were no bars at all. Beside this it seems to calculate the usable space wrong if there is a notch also there. Then, if landscape is set (programmatically), the graphics are cut off on the bottom by the size of the task bar.
      With my code now the hit position corresponds to the position of the button. Now I need a way to get rid of the task bar. Anyone an idea?

      A.T.

      T Offline
      T Offline
      TheoSys
      wrote last edited by
      #3

      Finally I solved the problem with the bars. Although I called the Java method to hide the bars they seemed to ignore the command. The problem was that I must call the hide() method after the application signaled that it is active. Every time the application becomes active the hide() method must be called. Additionally in the Android resource tree the file themes.xml must not contain any control statements for the system bars. My new themes.xml looks like this now:

      <resources>
          <!-- base set of styles that apply to all versions -->
          <style name="TPanelAppTheme" parent="@android:style/Theme.DeviceDefault">
          </style>
          <!-- declare the theme name that's actually applied in the manifest file -->
          <style name="TPanelAppTheme.NoActionBar">
          </style>
          <style name="Tpanel_settings" parent="Theme.AppCompat">
          </style>
      </resources>
      

      Everything else is controlled by code. Hope this helps someone.

      A.T.

      1 Reply Last reply
      1
      • T TheoSys

        Hi,

        my Android app uses the full screen. To be able to use it I'm hiding the bars. Hiding seems to work but with Android 16 a black beam is left on top. The graphics are below this black bar but the key strokes are taken as like the bar doesn't exist. Look at the screen shot. The red frame marks the bar and the blue frame shows the area where it thinks the button is:
        tpanel
        While the program is written in C++, the part to hide the bars is in Java. Here is the code:

        package org.qtproject.theosys;
        
        import android.os.Bundle;
        import android.os.Build;
        import android.app.Activity;
        import android.app.ActionBar;
        import android.view.View;
        import android.view.Window;
        import android.view.WindowInsets;
        import android.view.WindowInsetsController;
        import android.view.WindowManager;
        import androidx.core.view.WindowCompat;
        
        import org.qtproject.theosys.Logger;
        
        public class HideToolbar extends Logger
        {
            static private boolean mBusy = false;
            static private boolean mInit = false;
        
            static public void hide(Activity act, boolean hide)
            {
                if (act == null)
                    return;
        
                if (mBusy)
                    return;
        
                mBusy = true;
                act.setTheme(R.style.TPanelAppTheme);
        
                act.runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        try
                        {
                            Window window = act.getWindow();
                            View decor = null;
        
                            if (window != null)
                            {
                                WindowInsetsController wic = null; //window.getInsetsController();
        
                                if (wic == null)
                                {
                                    decor = window.getDecorView();
        
                                    if (decor != null)
                                        wic = decor.getWindowInsetsController();
                                }
        
                                if (wic != null)
                                {
                                    if (!mInit)
                                    {
                                        wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
                                        WindowCompat.enableEdgeToEdge(window);
                                        mInit = true;
                                    }
        
                                    if (hide)
                                    {
                                        wic.hide(WindowInsets.Type.systemBars());   // All types of bars
                                        log(HLOG_DEBUG, "HideToolbar.hide: Statusbars were hidden.");
                                    }
                                    else
                                    {
                                        wic.show(WindowInsets.Type.systemBars());   // All types of bars
                                        log(HLOG_DEBUG, "HideToolbar.hide: Statusbars were shown.");
                                    }
                                }
                                else
                                    log(HLOG_WARNING, "HideToolbar.hide: Error retrieving WindowInsetsController!");
                            }
                            else
                                log(HLOG_WARNING, "HideToolbar.hide: Error retrieving window!");
                        }
                        catch (Exception e)
                        {
                            log(HLOG_ERROR, "HideToolbar.hide: " + e);
                        }
                    }
                });
        
                mBusy = false;
            }
        }
        
        

        To see the whole program, look at tpanel on Github.
        To initialize the theme I use the following XML:

        <resources>
            <style name="TPanelAppTheme" parent="Theme.AppCompat.NoActionBar">
            </style>
            <style name="TPanelAppTheme.NoActionBar">
                <item name="android:windowActionBar">false</item>
                <item name="android:windowNoTitle">true</item>
                <item name="android:windowFullscreen">true</item>
                <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
            </style>
        </resources>
        

        This worked up to Android 14. Now with edge-to-edge it make troubles. Does anybody has an idea how I can get rid of the black bar?

        A.T.

        T Offline
        T Offline
        TheoSys
        wrote last edited by
        #2

        In the mean time I found out how to remove the bars on Android 16. I changed the Java code a little:

                            Window window = act.getWindow();
        
                            if (window != null)
                            {
                                WindowInsetsController wic = window.getInsetsController();
        
                                if (wic != null)
                                {
                                    if (hide)
                                    {
                                        wic.hide(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());   // All types of bars
                                        wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
                                    }
                                    else
                                    {
                                        wic.show(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());   // All types of bars
                                        wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
                                    }
                                }
                            }
        

        The additional parameter WindowInsets.Type.displayCutout() removed the black bars (on a Pixel9 pro they were on the left and on top) but it leaves the task bar visible with transparent background. Buttons under the bar are not clickable. On a Pixel 9Pro it looks currently like this:
        TPanel on Pixel9
        It seems that, if not overwritten by code, Qt honors the notch as well as the bars and places the first pixel (left upper corner) inside the usable space. But it does not correct the hit position. Hitting a button behaves as there were no bars at all. Beside this it seems to calculate the usable space wrong if there is a notch also there. Then, if landscape is set (programmatically), the graphics are cut off on the bottom by the size of the task bar.
        With my code now the hit position corresponds to the position of the button. Now I need a way to get rid of the task bar. Anyone an idea?

        A.T.

        T 1 Reply Last reply
        1
        • T TheoSys

          In the mean time I found out how to remove the bars on Android 16. I changed the Java code a little:

                              Window window = act.getWindow();
          
                              if (window != null)
                              {
                                  WindowInsetsController wic = window.getInsetsController();
          
                                  if (wic != null)
                                  {
                                      if (hide)
                                      {
                                          wic.hide(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());   // All types of bars
                                          wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
                                      }
                                      else
                                      {
                                          wic.show(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());   // All types of bars
                                          wic.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
                                      }
                                  }
                              }
          

          The additional parameter WindowInsets.Type.displayCutout() removed the black bars (on a Pixel9 pro they were on the left and on top) but it leaves the task bar visible with transparent background. Buttons under the bar are not clickable. On a Pixel 9Pro it looks currently like this:
          TPanel on Pixel9
          It seems that, if not overwritten by code, Qt honors the notch as well as the bars and places the first pixel (left upper corner) inside the usable space. But it does not correct the hit position. Hitting a button behaves as there were no bars at all. Beside this it seems to calculate the usable space wrong if there is a notch also there. Then, if landscape is set (programmatically), the graphics are cut off on the bottom by the size of the task bar.
          With my code now the hit position corresponds to the position of the button. Now I need a way to get rid of the task bar. Anyone an idea?

          A.T.

          T Offline
          T Offline
          TheoSys
          wrote last edited by
          #3

          Finally I solved the problem with the bars. Although I called the Java method to hide the bars they seemed to ignore the command. The problem was that I must call the hide() method after the application signaled that it is active. Every time the application becomes active the hide() method must be called. Additionally in the Android resource tree the file themes.xml must not contain any control statements for the system bars. My new themes.xml looks like this now:

          <resources>
              <!-- base set of styles that apply to all versions -->
              <style name="TPanelAppTheme" parent="@android:style/Theme.DeviceDefault">
              </style>
              <!-- declare the theme name that's actually applied in the manifest file -->
              <style name="TPanelAppTheme.NoActionBar">
              </style>
              <style name="Tpanel_settings" parent="Theme.AppCompat">
              </style>
          </resources>
          

          Everything else is controlled by code. Hope this helps someone.

          A.T.

          1 Reply Last reply
          1
          • T TheoSys has marked this topic as solved

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved