Search code examples
androidandroid-fragmentsandroid-actionbar

Action Bar title and menu disappear when replacing fragment, after updating from targetSdkVersion 30 to 33


The application worked fine until I had to upgrade. Some libraries were updated also, but reverting the libraries back don't seem to fix it. It seems to me that it is something related with the fragment transaction and the lifecycle of the fragment/activity. When the fragment transaction is committed, the action bar (MaterialToolbar as support action bar) becomes blank.

Did anybody encountered this behaviour after upgrading?


Solution

  • The issue was due to the ActionBar being present in the fragment layout file instead of the activity one. This used to work before. Moving the ActionBar (MaterialToolbar as support action bar) to the activity layout fixes the issue, but it introduces other problems.