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:
- Build and run the below code on Android.
- Tap on the "Add/Remove" button.
- Notice that the toolbar added to the top is overlapped by the status bar. (This is the bug.)
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.
Add the Toolbar to the Window before opening it and use Toolbar methods show() and hide() to control its visibility instead.