I have 1 Activity with 3 Fragments inside (Home-Login-RestorePass) Initially, HomeFragment shows and the other two are hidden. I want that the ActionBar Title change depending on which Fragment is showing.
I'm trying in my Activity with:
public void setActionBarTitle(String title){
getSupportActionBar().setTitle(title);
}
@Override
public void onResume() {
super.onResume();
// Set title
setActionBarTitle(getString(R.string.app_name));
}
and the fragments has the same:
@Override
public void onResume() {
super.onResume();
// Set title
((LoginActivity) getActivity()).setActionBarTitle(getString(R.string.fragment_login));
}
But it doesn't work. It always show R.string.fragment_login on the title.
I'm using FragmentTransaction for the fragment transition:
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
HomeFragment homeFragment = (HomeFragment) getFragmentManager().findFragmentById(R.id.fragmentHome);
LoginFragment loginFragment = (LoginFragment) getFragmentManager().findFragmentById(R.id.fragmentLogin);
ft.hide(homeFragment).addToBackStack(null);
ft.show(loginFragment).addToBackStack(null).commit();
}
});
Additionally if i could make appear an Arrow Button (Back) on ActionBar depending of the fragment would be great.
Thanks for your time! Regards.