I have been using the latest Toolbar from AppCompatv7 lib.I have placed a textview in the ToolBar ViewGroup And I want to set a title into this Textview from the fragment in my
getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
@Override
public void onBackStackChanged() {
FragmentManager.BackStackEntry lastBackStackEntry=null;
int lastBackStackEntryCount = getSupportFragmentManager().getBackStackEntryCount() - 1;
if(lastBackStackEntryCount >= 0 )
{
lastBackStackEntry = getSupportFragmentManager().getBackStackEntryAt(lastBackStackEntryCount);
}
Toast.makeText(MainActivity.this, ""+lastBackStackEntryCount, Toast.LENGTH_SHORT).show();
if(lastBackStackEntryCount == -1)
{
toolbar.setTitle("");
toolbar.setLogo(R.drawable.header_logo);
}
else
{
toolbar.setTitle(lastBackStackEntry.getName());
}
}
});