Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-27438

Android: Toolbar "extendBackground" property ignored if added to window after open

    Details

    • Type: Bug
    • Status: Open
    • Priority: Low
    • Resolution: Unresolved
    • Affects Version/s: Release 6.2.0
    • Fix Version/s: None
    • Component/s: Android

      Description

      Summary:
      If you add Toolbar to a Window after it has been opened, then Toolbar property "extendBackground" is ignored. The Toolbar will instead be overlapped by the top status bar.

      Steps to reproduce:

      1. Build and run the below code on Android.
      2. Tap on the "Add/Remove" button.
      3. Notice that the toolbar added to the top is overlapped by the status bar. (This is the bug.)

      var wasAdded = false;
      var windowSettings = {
      	extendSafeArea: true,
      };
      if (Ti.Android) {
      	windowSettings.windowFlags = Ti.UI.Android.FLAG_TRANSLUCENT_STATUS;
      	windowSettings.theme = "Theme.AppCompat.NoTitleBar";
      }
      var window = Ti.UI.createWindow(windowSettings);
      var toolbar = Ti.UI.createToolbar({
      	title: "My Toolbar",
      	titleTextColor: "white",
      	backgroundColor: "blue",
      	extendBackground: true,
      	top: 0,
      //	bottom: 0,
      	width: Ti.UI.FILL,
      });
      var button = Ti.UI.createButton({
      	title: "Add/Remove Toolbar",
      })
      button.addEventListener("click", function() {
      	if (wasAdded) {
      		window.remove(toolbar);
      	} else {
      		window.add(toolbar);
      	}
      	wasAdded = !wasAdded;
      });
      window.add(button);
      window.open();
      

      Result:

      Expected Result:

      Recommended Solution:
      Our toolbar Java code should call the requestApplyInsets() method when attached to the window. This requests the view hierarchy to re-dispatch the window insets to all child views, which is used to apply an internal padding to the toolbar needed to make "extendBackground" work.

      We'll need to add something like the following to our Toolbar code.

      @Override
      public void onAttachedToWindow()
      {
      	super.onAttachedToWindow();
       
      	if (getFitsSystemWindows()) {
      		if (android.os.Build.VERSION.SDK_INT >= 20) {
      			requestApplyInsets();
      		} else {
      			requestFitSystemWindows();
      		}
      	}
      }
      

      Work-around:
      Add the Toolbar to the Window before opening it and use Toolbar methods show() and hide() to control its visibility instead.

        Attachments

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Source Code