I try to change the title of my MainActivity outside the onCreate()
method. It seems to work inside onCreate()
, but if I try to change it programmatically, it doesn't do anything.
My onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(selectedSong);
I already tried outside the onCreate()
:
public void updatetitle(String title) {
toolbar.setTitle(title);
getSupportActionBar().setTitle(selectedSong);
((MainActivity) this).getSupportActionBar().setTitle(selectedSong);
setTitle(selectedSong);
}
None of these works. When I debug the code. The code in the toolbar object is updated, but the view isn't refreshed. Any hints? Thanks.