0

I got an android app, where I am currently working on the tablet layout.

Everything works fine, besides if you try to switch from tablet layout to normal portrait layout, then the title is not set anymore. Instead the default title is displayed as static and can't be changed with the normal setTitle method anymore. It is called as I see in the debug log, but this isn't reflected in the layout.

If you rotate back to tablet layout the title is back.

@Override
public void setTitle(int titleId)
{
    Toast.makeText(NavigationFragmentActivity.this, titleId, Toast.LENGTH_SHORT).show();
    super.setTitle(titleId);
    getSupportActionBar().setTitle(titleId);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
}

Thanks for any help.

max
  • 1
  • 2

1 Answers1

0

do not forget that when you rotate, the activity is distroy and an other is create, if you whant to keep the 'dynamic title' you should use this following method to pass the title from the finishing activity to the new one : OnSaveInstanceState() you will then be able to get the title in the new activity in the onCreate() method. For more information see : https://developer.android.com/training/basics/activity-lifecycle/recreating.html I hope it will help

abdoulayeYATERA
  • 209
  • 1
  • 2
  • I get the String of the title, but I can't set it again, after rotating. – max Jun 09 '16 at 10:28
  • It's a bug as documented here http://stackoverflow.com/questions/33103079/toolbar-supportactionbar-title-changes-to-app-name-on-orientation-change . Did you solve your issue? – Luke Allison Jun 14 '16 at 02:36